Find where python is installed (if it isn't default dir)
Question:
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?
Answers:
In unix (mac os X included) terminal you can do
which python
and it will tell you.
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
.
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:Python26libsite-packagessetuptools-0.6c11-py2.6.egg
c:Python26libsite-packagesnose-1.0.0-py2.6.egg
C:Windowssystem32python26.zip
c:Python26DLLs
c:Python26lib
c:Python26libplat-win
c:Python26liblib-tk
c:Python26
c:Python26libsite-packages
c:Python26libsite-packageswin32
c:Python26libsite-packageswin32lib
c:Python26libsite-packagesPythonwin
c:Python26libsite-packageswx-2.8-msw-unicode
Have a look at sys.path
:
>>> import sys
>>> print(sys.path)
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)"
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.
For Windows CMD run: where python
For Windows PowerShell run: Get-Command 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
On windows search python,then right click and click on “Open file location”.That’s how I did
- First search for PYTHON IDLE from search bar
-
Open the IDLE and use below commands.
import sys
print(sys.path)
-
It will give you the path where the python.exe is installed. For eg:
C:Users\…python.exe
-
Add the same path to system environment variable.
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 .
Run below command
where python
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?
In unix (mac os X included) terminal you can do
which python
and it will tell you.
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
.
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:Python26libsite-packagessetuptools-0.6c11-py2.6.egg
c:Python26libsite-packagesnose-1.0.0-py2.6.egg
C:Windowssystem32python26.zip
c:Python26DLLs
c:Python26lib
c:Python26libplat-win
c:Python26liblib-tk
c:Python26
c:Python26libsite-packages
c:Python26libsite-packageswin32
c:Python26libsite-packageswin32lib
c:Python26libsite-packagesPythonwin
c:Python26libsite-packageswx-2.8-msw-unicode
Have a look at sys.path
:
>>> import sys
>>> print(sys.path)
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)"
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.
For Windows CMD run: where python
For Windows PowerShell run: Get-Command 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
On windows search python,then right click and click on “Open file location”.That’s how I did
- First search for PYTHON IDLE from search bar
-
Open the IDLE and use below commands.
import sys
print(sys.path) -
It will give you the path where the python.exe is installed. For eg:
C:Users\…python.exe -
Add the same path to system environment variable.
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 .
Run below command
where python