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 Overflow
🌐
Python
docs.python.org › 3 › using › cmdline.html
1. Command line and environment — Python 3.14.6 documentation
If this option is given, the first ... on the command line. If the script name refers directly to a Python file, the directory containing that file is added to the start of sys.path, and the file is executed as the __main__ module. If the script name refers to a directory or zipfile, the script name is added to the start of sys.path and the __main__.py file in that location is executed as the __main__ module. -I option can be used to run the script in isolated mode where sys.path contains ...
Discussions

shell - Is there a Python equivalent to the 'which' command - Stack Overflow
Put another way, is there a cross-platform way of knowing which file will be executed by subprocess.Popen(file) without first executing it? More on stackoverflow.com
🌐 stackoverflow.com
Python not found by command prompt
I have installed Python in Windows 11 and saved a small script called unicode.replacer.py In the command prompt, in the correct directory, when I attempt to execute: python unicode.replacer.py command prompt reports: Python was not found. Any suggestions welcome. More on discuss.python.org
🌐 discuss.python.org
19
0
February 11, 2024
startup - What command can be used to find where Python is installed? - Unix & Linux Stack Exchange
what command? and why is so important? In UNIX? I have heilo and need to correct command. More on unix.stackexchange.com
🌐 unix.stackexchange.com
Python appears in cmd
Hello I downloaded Python 310 and then installed it on my system. Well, everything was okay up to this stage. After I opened python.exe, it appeared in cmd, not python! Please guide me what I must to do? Thank you … More on discuss.python.org
🌐 discuss.python.org
15
0
May 19, 2022
🌐
Reddit
reddit.com › r/learnpython › quick question: how do i view python's location in command prompt?
r/learnpython on Reddit: Quick Question: How do I view Python's location in command prompt?
November 11, 2021 -

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?

🌐
CodeWithHarry
codewithharry.com › blogpost › how-to-find-python-installation-path
How to find the Python Installation Path on Windows? | Blog | CodeWithHarry
In the Command Prompt window, type the following command: ... Press Enter, and the system will display the paths where Python is installed.
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-command.html
Command Line
The first word "python3" means we want to run the Python interpreter which handles python programs, and then "hello.py" refers to the Python program we want to run. Those two words run the Python program in the "hello.py" file, printing any output to the terminal. On Windows instead of "python3" the command is "python" or "py" and everything else is the same.
🌐
Python documentation
docs.python.org › 3 › tutorial › interpreter.html
2. Using the Python Interpreter — Python 3.14.6 documentation
On Windows machines where you have installed Python from the Microsoft Store, the python3.14 command will be available. If you have the py.exe launcher installed, you can use the py command.
🌐
Medium
medium.com › @viknesh2798 › how-to-fix-the-issues-while-using-python-command-in-the-command-prompt-ba56d9018c5f
[SOLVED] Windows: Python command not found in CMD and Microsoft store pops up when I type python in CMD..! | by Viknesh M R | Medium
April 30, 2022 - This is because, the windows system will check the command in the path and prioritize the path from top to bottom. If you move the python path above the Microsoft store path.
Find elsewhere
🌐
InterviewBit
interviewbit.com › commands › python commands list: with examples
Python Commands List: With Examples - InterviewBit
August 16, 2023 - In the Python programming language, commands basically refer to different functions or methods that we can execute on the python shell to work them as commands. According to the official documentation of Python, there are no “commands” in Python ...
🌐
W3Schools
w3schools.com › python › python_getstarted.asp
Python Getting Started
C:\Users\Your Name>python Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello, World!") Which will write "Hello, World!" in the command line:
🌐
AskPython
askpython.com › python › examples › determine-install-path-of-python-cli
Determining the Install Path of Python from the Command Line - AskPython
June 30, 2023 - Now we’ll run the following command in our command prompt to find the location of Python in our computer. ... Now press “Enter”. The keyword “where” will give you the absolute path of Python as shown below.
🌐
Humboldt State University
gsp.humboldt.edu › olm › Courses › GSP_318 › 08_3_1_RunningPythonFromTheCommandLine.html
GIS Programming With Python - Running Scripts from the Command Line
Once you're in the folder that contains "python.exe" it's easy to run a script. Just type"python <full path to the script>" and you'll see the "print" output appear below the command. Try that now for the script you just created. You should see the "Hello World" appear in the window.
Top answer
1 of 3
98

Python 3.3 added shutil.which() to provide a cross-platform means of discovering executables:

http://docs.python.org/3/library/shutil.html#shutil.which

Return the path to an executable which would be run if the given cmd was called. If no cmd would be called, return None.

Sample calls:

>>> shutil.which("python")
'/usr/local/bin/python'

>>> shutil.which("python")
'C:\\Python33\\python.EXE'

Unfortunately, this has not been backported to 2.7.x.

2 of 3
17

An option for Python 2 and 3:

from distutils.spawn import find_executable

find_executable('python')  # '/usr/bin/python'

find_executable('does_not_exist')  # None

find_executable(executable, path=None) simply tries to find 'executable' in the directories listed in 'path'. Defaults to os.environ['PATH'] if 'path' is None. Returns the complete path to 'executable' or None if not found.

Keep in mind that unlike which, find_executable does not actually check that the result is marked as executable. You may want to call os.access(path, os.X_OK) to check that on your own if you want to be certain that subprocess.Popen will be able to execute the file.


Also of note, shutil.which of Python 3.3+ has been backported and made available for Python 2.6, 2.7, and 3.x via the 3rd-party module whichcraft.

It is available for installation via the aforementioned GitHub page (i.e. pip install git+https://github.com/pydanny/whichcraft.git) or the Python package index (i.e. pip install whichcraft). It can be used like such:

from whichcraft import which

which('wget')  # '/usr/bin/wget'
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › dev-environment › python
Python on Windows for beginners | Microsoft Learn
The py.exe launcher will automatically select the most recent version of Python you've installed. You can also use commands like py -3.7 to select a particular version, or py --list to see which versions can be used. HOWEVER, the py.exe launcher will only work if you are using a version of Python installed from python.org.
🌐
Python.org
discuss.python.org › python help
Python not found by command prompt - Python Help - Discussions on Python.org
February 11, 2024 - I have installed Python in Windows 11 and saved a small script called unicode.replacer.py In the command prompt, in the correct directory, when I attempt to execute: python unicode.replacer.py command prompt reports: …
🌐
Real Python
realpython.com › run-python-scripts
How to Run Your Python Scripts and Code – Real Python
February 25, 2026 - After you press Enter, you’ll see the phrase Hello, World! on your screen. If the previous command doesn’t work right, then you may need to check if Python is in your system’s PATH. You can also check where you saved hello.py.
🌐
Flexiple
flexiple.com › python › python-commands
Python Commands List with Example - Flexiple - Flexiple
The find() command is used to search for a substring within a string. It returns the index of the first occurrence of the substring if it's present, or -1 if it's not found. ... In this case, the find() method locates the substring "is" within the sentence "Python is powerful" and returns the index where it starts (7 in this case).
🌐
W3docs
w3docs.com › python
How can I find where Python is installed on Windows? | W3Docs
If you have multiple versions of Python installed, the where command will show the location of all of them.
🌐
Kinsta®
kinsta.com › home › resource center › blog › python › 20+ essential python commands you should know
20+ Essential Python Commands You Should Know
December 15, 2023 - These shells interpret the commands given by the user, execute them and return a result often referred to as output. A CLI can execute different shells. This screenshot shows two different CLIs, one with the Python shell and another with Bash: Python and Bash shells. These two concepts are often confused, so here’s the breakdown: CLI is the text-based interface where you type in commands and get the output of those commands.
🌐
Python.org
discuss.python.org › python help
Python appears in cmd - Python Help - Discussions on Python.org
May 19, 2022 - Hello I downloaded Python 310 and then installed it on my system. Well, everything was okay up to this stage. After I opened python.exe, it appeared in cmd, not python! Please guide me what I must to do? Thank you …