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

Python

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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

which python

and it will tell you.

Solution 3 - Python

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

Solution 4 - Python

For Windows CMD run: where python

For Windows PowerShell run: Get-Command python

Solution 5 - Python

Have a look at sys.path:

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

Solution 6 - 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.

Solution 7 - Python

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.

Solution 8 - Python

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 .

Solution 9 - 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

Solution 10 - Python

  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.

Solution 11 - Python

On windows search python,then right click and click on "Open file location".That's how I did

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKilizoView Question on Stackoverflow
Solution 1 - PythonNed BatchelderView Answer on Stackoverflow
Solution 2 - PythondhgView Answer on Stackoverflow
Solution 3 - PythonschlamarView Answer on Stackoverflow
Solution 4 - PythonSitiSchuView Answer on Stackoverflow
Solution 5 - PythonMRABView Answer on Stackoverflow
Solution 6 - Pythontiny_mouseView Answer on Stackoverflow
Solution 7 - PythonWebucatorView Answer on Stackoverflow
Solution 8 - PythonBadri PaudelView Answer on Stackoverflow
Solution 9 - PythonKellen StuartView Answer on Stackoverflow
Solution 10 - PythonAnku gView Answer on Stackoverflow
Solution 11 - Pythonuser11916012View Answer on Stackoverflow