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?
11 Answers
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
![](../../users/profiles/14343.webp)
- 323,515
- 67
- 518
- 625
-
When I type `sys` in Python it says it is not defined... what is going on there? Thanks. – Spacey Oct 15 '14 at 21:32
-
2
-
13Pythonic! This is an OS agnostic answer and doesn't require access to command line. This worked well for me since I only have access to the Python Interpreter. – Robino Jan 08 '16 at 09:29
-
6Please accept this answer as it is multi-platform and doesn't need access to the shell/cmd! – Hack5 Apr 20 '17 at 13:33
-
This also works better when you have multiple pythons installations and access them through py -2 or py -3 for example, since 'which python' will probably display only one – GuiFGDeo Jul 02 '18 at 16:49
In unix (mac os X included) terminal you can do
which python
and it will tell you.
-
4@Ned check out http://stackoverflow.com/questions/304319/is-there-an-equivalent-of-which-on-windows – Foo Bah Jul 21 '11 at 04:06
-
@Foo Bah: yes, thanks. Did you see mine was the accepted answer there? :) – Ned Batchelder Jul 21 '11 at 14:53
-
@Ned no offense but I had actually intended to point to the answer that had the most upvotes (it used CMD primitives :) – Foo Bah Jul 21 '11 at 16:11
-
20-1: Definitely not the best answer here. There are both single line and multiline solutions that work on every answer. – ArtOfWarfare Aug 24 '13 at 21:00
-
8This is also not the best answer because many, many more times often than not, your `python` executable is a symlink. `which python` will, in all probability just point to `/usr/bin` or `/usr/local/bin`, which really isn't helpful. – Jay Sep 02 '15 at 14:56
-
An alternative to looking for Windows equivalents to these commands is to install a bash shell on Windows. The "which python" command works when run in Git Bash on Windows. – Asencion Feb 28 '19 at 20:13
-
"which python" works for me on Windows in Bash but not a command prompt. "where python" works in a command prompt. – Micah B. Oct 02 '19 at 20:47
-
is there any command or method of module to find from python file where the python interpretor is? – Mahdi-Jafaree Jun 23 '20 at 09:01
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)"
![](../../users/profiles/606725.webp)
- 5,598
- 5
- 43
- 55
![](../../users/profiles/851737.webp)
- 8,550
- 3
- 35
- 71
-
10Worked great on windows! If you're on python 3 you'll have to change it to `print(sys.executable)` – Crazometer May 19 '16 at 04:55
-
the python 3 version should work on python 2 regardless, as the parentheses are just treated as a token – micsthepick Mar 21 '20 at 00:09
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.
![](../../users/profiles/693679.webp)
- 479
- 2
- 9
-
1
-
3
-
-
7
-
1This is how I know that /System/Library/Frameworks/Python.framework/Versions/2.5/lib/ is the same directory as /usr/bin? – Wooble Jul 20 '11 at 20:02
-
1If you don't have the `re` module, then try it with a module that you **do** have. Anything you're expecting to be in the `lib` subdirectory should work, such as `os` (which is pretty essential). – Karl Knechtel Jul 20 '11 at 21:50
-
1@Karl Yup. I just picked something that came standard and assumed anyone reading it would be able to figure out you could substitute any standard module. My mistake. ;) – tiny_mouse Jul 21 '11 at 07:15
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 .
![](../../users/profiles/9898251.webp)
- 489
- 8
- 9
- 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.
![](../../users/profiles/6062265.webp)
- 61
- 7
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
![](../../users/profiles/5361412.webp)
- 4,727
- 1
- 35
- 59
-
-
1@misantroop I dare you to find an instance of windows without powershell; unless you're running Windows Server 2003, it will have powershell – Kolob Canyon Nov 18 '18 at 07:38
-
1Not natively on XP and all of the versions derived from it. Installing software to determine where Python is located seems overkill. – misantroop Nov 18 '18 at 08:00
-
@misantroop yes. XP is a version derived from Windows Server 2003. You will be lucky to find a Windows machine that doesn't have powershell. – Kolob Canyon Nov 19 '18 at 16:06
-
On windows search python,then right click and click on "Open file location".That's how I did