Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find where python is installed (if it isn't default dir)

Tags:

python

People also ask

How do I know where Python is installed?

Manually Locate Where Python is InstalledType 'Python' in the Windows Search Bar. Right-click on the Python App, and then select “Open file location“ Right-click on the Python shortcut, and then select Properties. Click on “Open File Location“

Where is Python default path?

/usr/local/bin/python is the default path of the Python directory.

Where is Python folder stored?

Python is generally installed in any one of the following given directories: C:\Users\AppData\ C:\PythonXY.


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

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

which python

and it will tell you.


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)"

For Windows CMD run: where python

For Windows PowerShell run: Get-Command python


Have a look at sys.path:

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