我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到Python的安装位置?
我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到Python的安装位置?
当前回答
如果你的环境变量中有Python,那么你可以在cmd或powershell中使用以下命令:
where python
或Unix环境
which python
命令行映像:
其他回答
在Python解释器中,输入以下命令:
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
此外,您可以将所有这些组合在一起,并使用单行命令。打开cmd,输入以下命令
python -c "import os, sys; print(os.path.dirname(sys.executable))"
如果你的环境变量中有Python,那么你可以在cmd或powershell中使用以下命令:
where python
或Unix环境
which python
命令行映像:
在我的windows安装,我得到这些结果:
>>> import sys
>>> sys.executable
'C:\\Python26\\python.exe'
>>> sys.platform
'win32'
>>>
(你也可以在sys。合理位置的路径)
在sys包中,你可以找到很多关于安装的有用信息:
import sys
print sys.executable
print sys.exec_prefix
我不确定这会在你的Windows系统上给出什么,但在我的Mac上,可执行文件指向Python二进制文件,exec_prefix指向安装根。
你也可以尝试检查你的sys模块:
import sys
for k,v in sys.__dict__.items():
if not callable(v):
print "%20s: %s" % (k,repr(v))
简单的方法是
打开CMD 在CMD中键入where python