In your Python interpreter, type the following commands:
>>> import os, sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
Also, you can club all these and use a single line command. Open cmd and enter following command
python -c "import os, sys; print(os.path.dirname(sys.executable))"
Answer from elo80ka on Stack OverflowIn your Python interpreter, type the following commands:
>>> import os, sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
Also, you can club all these and use a single line command. Open cmd and enter following command
python -c "import os, sys; print(os.path.dirname(sys.executable))"
If you have Python in your environment variable then you can use the following command in cmd or powershell:
where python
or for Unix enviroment
which python
command line image :

Finding where 3.13 is installed
Quick Question: How do I view Python's location in command prompt?
Find where python is installed (if it isn't default dir) - Stack Overflow
Why doesnt Python add itself to PATH on Windows?
Videos
So I've been having trouble with Python and I want to know which installation I'm using (I have two user profiles on Windows, my old one and the one I made explicitly to code in, and they both have Python installed).
I tried looking it up, but it only led to this madness you see below:
Microsoft Windows [Version 10.0.19043.1348]
(c) Microsoft Corporation. All rights reserved.
C:\Users\willi>!type python
'!type' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\willi>type python
The system cannot find the file specified.
C:\Users\willi>type Python
The system cannot find the file specified.
C:\Users\willi>Python type
Python: can't open file 'C:\Users\willi\type': [Errno 2] No such file or directory
C:\Users\willi>Python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
>>> .quit
File "<stdin>", line 1
.quit
^
SyntaxError: invalid syntax
>>> quit
Use quit() or Ctrl-Z plus Return to exit
>>> quit()
C:\Users\willi>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> !type Python
File "<stdin>", line 1
!type Python
^
SyntaxError: invalid syntax
>>> type
<class 'type'>
>>> type python
File "<stdin>", line 1
type python
^
SyntaxError: invalid syntax
>>> type Python
File "<stdin>", line 1
type Python
^
SyntaxError: invalid syntax
>>> type(Python)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Python' is not defined
>>>How do I view Python's location in command prompt?
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.