Python 如何让 pydoc 命令在 Windows 中工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3689350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get pydoc command working in Windows?
提问by
pydocdoes not work in Windows. at this post Pydoc is not working (Windows XP)the last answer by dave webb says to create a pydoc.batfile with this code in it:
pydoc在 Windows 中不起作用。在这篇文章中,Pydoc 无法正常工作(Windows XP)dave webb 的最后一个答案说要创建一个包含以下代码的pydoc.bat文件:
@python c:\Python27\Lib\pydoc.py %*
After I create pydoc.bat where should it be placed so the pydoccommand works in the command prompt?
在我创建 pydoc.bat 之后,它应该放在哪里,以便pydoc命令在命令提示符下工作?
PSadding C:\python27\Lib\pydoc.pyto the Windows path in the system environment variables does not work. Even after logging out and back in it does not work.
PSC:\python27\Lib\pydoc.py在系统环境变量中添加到Windows路径不起作用。即使在注销并重新登录后也不起作用。
采纳答案by ars
PS adding C:\python27\Lib\pydoc.py to the Windows path in the system environment variables does not work. Even after logging out and back in it does not work.
PS 在系统环境变量中将 C:\python27\Lib\pydoc.py 添加到 Windows 路径不起作用。即使在注销并重新登录后也不起作用。
The PATHenvironment variable is a list of directoriesto search for a given executable. So you should be adding C:\python27\Libto your PATH(not including the filename).
该PATH环境变量的列表目录,以搜索给定的可执行文件。所以你应该添加C:\python27\Lib到你的PATH(不包括文件名)。
As for the pydoc.batfile you've created, one place to put it would be the C:\python27\Scriptsdirectory which is usually added to your PATHby the python installation (since that folder contains miscellaneous scripts that you might like available at the command line).
至于pydoc.bat您创建的文件,放置它的一个地方C:\python27\Scripts是通常PATH由 python 安装添加到您的目录(因为该文件夹包含您可能喜欢在命令行中可用的杂项脚本)。
回答by nosklo
put it in any folder that is in your PATH. Example: C:\Windows\System32
将它放在 PATH 中的任何文件夹中。例子:C:\Windows\System32
Alternatively, you can put it anywhere, and then add the folderit is in to windows PATH
或者,你可以把它放在任何地方,然后将它所在的文件夹添加到 windows PATH
回答by Lstor
If you add .PY to your PATHEXTenvironment variable, you don't need the batch script. Just add C:\Python27\Libto PATH, and you're all set.
如果将 .PY 添加到PATHEXT环境变量中,则不需要批处理脚本。只需添加C:\Python27\Lib到PATH,就可以了。
回答by Hussam
As an example for Raw_input, try: python -m pydoc raw_input
作为 Raw_input 的示例,请尝试: python -m pydoc raw_input
回答by mike
I have a simple PowerShell script sitting in my "\python27\" directory called 'pydoc.ps1'. I can then call pydoc as intended...
我的“\python27\”目录中有一个简单的 PowerShell 脚本,名为“pydoc.ps1”。然后我可以按预期调用 pydoc ......
ie.
c:> pydoc raw_input
IE。
c:> pydoc raw_input
code for 'pydoc.psi':
'pydoc.psi' 的代码:
foreach ($i in $args)
{python \python27\lib\pydoc.py $i}
回答by invincible
Use python -m pydoc osinstead of pydocdirectly, no need to add to path variable.
python -m pydoc os代替pydoc直接使用,不需要添加到路径变量中。
the -m tells python that pydoc is a pre-built module in python and NOT a script (.py file) sitting in the current working folder.
-m 告诉 python pydoc 是 python 中的预构建模块,而不是位于当前工作文件夹中的脚本(.py 文件)。
See https://docs.python.org/3/using/cmdline.htmlfor details
回答by Adam
I have found in windows 10 powershell...
我在 Windows 10 powershell 中发现...
Remember to access pydoc in windows, it's python -m pydoc. If you want to access info on "file", add the word "file" after. Like this "python -m pydoc file" (*w/o the quotes).
记得在windows中访问pydoc,它是python -m pydoc。如果要访问有关“文件”的信息,请在后面添加“文件”一词。像这个“python -m pydoc 文件”(*不带引号)。
What you type after python -m pydoc, will tell it what info you want brought up and/or looking for. i.e. python -m pydoc raw_input, python -m pydoc string, python -m pydoc file.
您在 python -m pydoc 之后输入的内容将告诉它您想要显示和/或查找的信息。即 python -m pydoc raw_input,python -m pydoc 字符串,python -m pydoc 文件。
Remmeber python -m pydoc must be in front of what you are looking for.
记住 python -m pydoc 必须在您要查找的内容之前。

