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


当前回答

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

where python   

在命令提示符(CMD)中

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

其他回答

看看sys.path:

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

在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的路径。

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

Python 2:

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

Python 3:

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

Windows用户:

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

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

cd \
ls *ython* -Recurse -Directory

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