Python在我的机器上,我只是不知道在哪里,如果我在终端中输入Python,它会打开Python 2.6.4,这不是在它的默认目录中,肯定有一种方法可以从这里找到它的安装位置?


在unix(包括mac os X)终端上可以这样做

which python

它会告诉你。


在类unix系统上,您应该能够键入哪个python,这将打印出python的路径。Windows命令提示符中的等效语句是where python, Windows Powershell中的Get-Command python。

另一种(跨平台)方法是将其输入IDLE或REPL(在终端中输入python):

import re
re.__file__

或者在你的终端上写一行:

python -c "import re; print(re.__file__)"

这将打印re模块的路径,从而显示python命令指向的位置。你可以放置你知道已经安装的任何其他模块,路径将指向该模块,也为你提供python的路径。


Sys有一些有用的东西:

$ python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'c:\\Python26\\python.exe'
>>> sys.exec_prefix
'c:\\Python26'
>>>
>>> print '\n'.join(sys.path)

c:\Python26\lib\site-packages\setuptools-0.6c11-py2.6.egg
c:\Python26\lib\site-packages\nose-1.0.0-py2.6.egg
C:\Windows\system32\python26.zip
c:\Python26\DLLs
c:\Python26\lib
c:\Python26\lib\plat-win
c:\Python26\lib\lib-tk
c:\Python26
c:\Python26\lib\site-packages
c:\Python26\lib\site-packages\win32
c:\Python26\lib\site-packages\win32\lib
c:\Python26\lib\site-packages\Pythonwin
c:\Python26\lib\site-packages\wx-2.8-msw-unicode

看看sys.path:

>>> import sys
>>> print(sys.path)

平台独立的解决方案在一条线上

Python 2:

python -c "import sys; print sys.executable"

Python 3:

python -c "import sys; print(sys.executable)"

要找到Windows上所有的Python安装,在命令提示符处运行:

dir site.py /s

确保您在根驱动器中。你会看到类似这样的东西。


对于Windows CMD,执行:where python . exe

Windows PowerShell: Get-Command python


Windows用户:

如果python命令不在您的$PATH环境中。

打开PowerShell并运行这些命令以找到该文件夹

cd \
ls *ython* -Recurse -Directory

这应该会告诉你python安装在哪里


在windows搜索python,然后右键单击“打开文件位置”。我就是这么做的


首先从搜索栏中搜索PYTHON IDLE 打开IDLE并使用以下命令。 导入系统 打印(sys.path) 它会告诉你安装python.exe的路径。如: C:\Users\ \…\ python.exe 为系统环境变量添加相同路径。


如果你使用的是windows操作系统(我使用的是windows 10),只需输入

where python   

在命令提示符(CMD)中

它将显示您所安装的目录。


运行以下命令

where python