Kilizo
Kilizo

Reputation: 3382

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

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?

Upvotes: 241

Views: 617884

Answers (13)

Badri Paudel
Badri Paudel

Reputation: 1630

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

where python   

in command prompt ( cmd )

If you are looking for MAC OS or Linux, you may use:

which python

or

which python3

All of these commands will be applicable in git bash regardless of OS.

Upvotes: 9

not2qubit
not2qubit

Reputation: 16912

OS Independent Solutions:

Nothing new here, but might be worth mentioning...

Unless you have changed the default installation path for pip, just open a shell and type pip list -v --version, the executable will then be found in the directory before Lib.

# pip list -v --version

Package  Version Location                            Installer
-------- ------- ----------------------------------- ---------
pip      23.3.1  C:\lang\Python312\Lib\site-packages pip
venvlink 0.5.0   C:\lang\Python312\Lib\site-packages pip

# OR use

# python -c "import sys; print(sys.executable)"
C:\lang\Python312\python.exe

Upvotes: 1

user11916012
user11916012

Reputation:

On Windows, search for "python", then right-click on it and click "Open file location".

Upvotes: 1

Mounesh
Mounesh

Reputation: 744

Run below command

where python

Upvotes: 0

tiny_mouse
tiny_mouse

Reputation: 489

On UNIX-like systems, you should be able to type which python, which will print out the path to python. The equivalent in Windows Command Prompt is where python, and Get-Command python in Windows Powershell.

Another (cross-platform) method is to type this into IDLE or REPL (type python into your terminal):

import re
re.__file__

Or in one line from your terminal:

python -c "import re; print(re.__file__)"

This will print the path to the re module, consequently showing you where the python command points to. You can put any other module that you know is installed, and the path will point to that module, also giving you the path to python.

Upvotes: 16

SitiSchu
SitiSchu

Reputation: 1417

For Windows CMD run: where python

For Windows PowerShell run: Get-Command python

Upvotes: 63

Anku g
Anku g

Reputation: 111

  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.

Upvotes: 3

dhg
dhg

Reputation: 52681

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

which python

and it will tell you.

Upvotes: 193

Kellen Stuart
Kellen Stuart

Reputation: 8893

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

Upvotes: 3

schlamar
schlamar

Reputation: 9511

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

Upvotes: 133

Webucator
Webucator

Reputation: 2683

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.

Upvotes: 10

Ned Batchelder
Ned Batchelder

Reputation: 375574

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

Upvotes: 270

MRAB
MRAB

Reputation: 20654

Have a look at sys.path:

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

Upvotes: 28

Related Questions