查找python的安装位置(如果不是默认目录)

问题:查找python的安装位置(如果不是默认目录)

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

Python is on my machine, I just don’t know where, if I type python in terminal it will open Python 2.6.4, this isn’t in it’s default directory, there surely is a way of finding it’s install location from here?


回答 0

在unix(包括mac os X)终端中,您可以执行

which python

它会告诉你。

In unix (mac os X included) terminal you can do

which python

and it will tell you.


回答 1

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 has some useful stuff:

$ 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

回答 2

一行独立于平台的解决方案是

Python 2:

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

Python 3:

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

Platform independent solution in one line is

Python 2:

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

Python 3:

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

回答 3

在Windows上运行where python应该可以。

On windows running where python should work.


回答 4

看一下sys.path

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

Have a look at sys.path:

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

回答 5

您应该能够键入“哪个python”,它将打印出python的路径。

或者您可以输入:

python
>>> import re
>>> re.__file__

它将显示re模块的路径,您将看到python在哪里。

You should be able to type “which python” and it will print out a path to python.

or you can type:

python
>>> import re
>>> re.__file__

and it will print a path to the re module and you’ll see where python is that way.


回答 6

要查找Windows上所有的Python安装,请在命令提示符下运行以下命令:

dir site.py /s

确保您在根驱动器中。您将看到类似这样的内容

To find all the installations of Python on Windows run this at the command prompt:

dir site.py /s

Make sure you are in the root drive. You will see something like this.


回答 7

如果您使用的是wiindows OS(我使用的是Windows 10),只需键入

where python   

在命令提示符(cmd)中

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

If you are using wiindows OS (I am using windows 10 ) just type

where python   

in command prompt ( cmd )

It will show you the directory where you have installed .


回答 8

对于Windows用户:

如果该python命令不在您的$PATH环境中,则为var。

打开PowerShell并运行以下命令以查找文件夹

cd \
ls *ython* -Recurse -Directory

那应该告诉你python安装在哪里

For Windows Users:

If the python command is not in your $PATH environment var.

Open PowerShell and run these commands to find the folder

cd \
ls *ython* -Recurse -Directory

That should tell you where python is installed


回答 9

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

On windows search python,then right click and click on “Open file location”.That’s how I did


回答 10

  1. 首先从搜索栏中搜索PYTHON IDLE
  2. 打开IDLE,然后使用以下命令。

    导入sys打印(sys.path)

  3. 它将为您提供python.exe的安装路径。例如: C:\ Users \\ … \ python.exe

  4. 将相同的路径添加到系统环境变量。

  1. First search for PYTHON IDLE from search bar
  2. Open the IDLE and use below commands.

    import sys print(sys.path)

  3. It will give you the path where the python.exe is installed. For eg: C:\Users\\…\python.exe

  4. Add the same path to system environment variable.