如何从命令行获取python安装路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19829516/
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 python installed path from command line
提问by user2499879
I am trying to get the installed path of python? Any idea how to get the python installed path from command line in windows. I don't want to set the environment variable?
我想获取python的安装路径?知道如何从 Windows 的命令行获取 python 安装路径。我不想设置环境变量?
Thanks,
谢谢,
采纳答案by roippi
try opening up cmd
and simply:
尝试打开cmd
并简单地:
where python
By default, this searches your PATH for matches. More precisely:
默认情况下,这会在您的 PATH 中搜索匹配项。更确切地说:
Description: Displays the location of files that match the search pattern. By default, the search is done along the current directory and in the paths specified by the PATH environment variable.
说明:显示与搜索模式匹配的文件的位置。默认情况下,搜索是沿着当前目录和 PATH 环境变量指定的路径完成的。
Most windows python installers modify your PATH so this should find what doing python
at the CLI will call.
大多数 Windows python 安装程序都会修改您的 PATH,因此这应该可以找到python
在 CLI 中执行的操作将调用的内容。
回答by histrio
You can check registry by:
HKLM SOFTWARE\Python\PythonCore\${PYTHON_VERSION}\InstallPath
您可以通过以下方式检查注册表:
HKLM SOFTWARE\Python\PythonCore\${PYTHON_VERSION}\InstallPath
or HKCU
或香港中大
回答by falsetru
Cross-platform solution using sys.executable
跨平台解决方案使用 sys.executable
python -c "import sys; print(sys.executable)"
sys.executable
A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense.
系统。可执行文件
在有意义的系统上,给出 Python 解释器的可执行二进制文件的绝对路径的字符串。