Find where python is installed (if it is not a standard dir)

Python on my machine, I just don’t know where, if I find python in the terminal, it will open Python 2.6.4, it is not in its default directory, there certainly is a way to find its installation location from here?

+131
python
Jul 20 '11 at 19:19
source share
9 answers

In a Unix terminal (including Mac OS X) you can do

which python 

and it will tell you.

+122
Jul 20 '11 at 19:21
source share

sys has 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 
+180
Jul 20 '11 at 19:24
source share

Platform Independent Single Line Solution

Python 2:

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

Python 3:

 python -c "import sys; print(sys.executable)" 
+85
Jul 20 '11 at 20:01
source share

Take a look at sys.path :

 >>> import sys >>> print(sys.path) 
+24
Jul 20 '11 at 19:25
source share

On windows with where python should work.

+19
May 17 '17 at 9:34 a.m.
source share

You should be able to enter "what python" and it will print the path to python.

or you can enter:

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

and it will output the path to the re module, and you will see where python is located.

+10
Jul 20 '11 at 19:23
source share

To find all Python installations on Windows, run this on the command line:

 dir site.py /s 

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

+8
Dec 02 '15 at 15:35
source share

For Windows users:

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

Open PowerShell and run these commands to find the folder

 cd \ ls *ython* -Recurse -Directory 

This should tell you where python is installed.

+2
Oct 24 '17 at 20:06 on
source share

On Windows Search Python, then right-click and click "Open File Location." The way i did

+1
Aug 13 '19 at 5:14
source share



All Articles