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 › windows.html
4. Using Python on Windows — Python 3.14.6 documentation
To obtain Python from the CPython team, use the Python Install Manager. This is a standalone tool that makes Python available as global commands on your Windows machine, integrates with the system, and supports updates over time.
Discussions

Quick Question: How do I view Python's location in command prompt?
Either via the command where from a cmd shell: where python Or via sys.executable from a Python shell: import sys sys.executable More on reddit.com
🌐 r/learnpython
4
1
November 11, 2021
How do I run a Python program in the Command Prompt in Windows 7? - Stack Overflow
I'm trying to figure out how to run Python programs with the Command Prompt on Windows 7. (I should have figured this out by now...) When I typed "python" into the command prompt, I got the More on stackoverflow.com
🌐 stackoverflow.com
Python 3 for Windows REPL in cmd window?
The default command in windows is py, not python More on reddit.com
🌐 r/learnpython
12
1
January 22, 2025
How do you *actually* use python on your computer?
Usually people will use an Integrated Development Environment (IDE) to program. This is not exclusive to Python. Practically all popular programming languages have an IDE that supports said language. In the case of Python, probably the most popular IDE is PyCharm, by JetBrains. Python doesn't need an IDE to run, though. The Python interpreter can be ran using any shell. If you don't know what a shell is: the most popular in Linux is bash (often just called the terminal), and Windows uses the command prompt (currently being phased out/revamped) or the PowerShell. These are just programs that search for and run programs supplied by user input (text). Whether you're running an IDE or a shell: running the interpreter is done more or less the same way: the interpreter is simply a program that is executed. It receives input (in the form of python code), and those instructions are interpreted to make the computer behave a certain way (store a variable in memory, run a loop, jump to a function, etc.). More on reddit.com
🌐 r/learnprogramming
116
687
February 22, 2020
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › dev-environment › python
Python on Windows for beginners | Microsoft Learn
For Linux, macOS, WSL and the Microsoft Store version of Python, you should use the python3 (or python3.7) command. Why does running python.exe open the Microsoft Store? To help new users find a good installation of Python, we added a shortcut to Windows that will take you directly to the latest ...
🌐
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.
🌐
Adafruit
learn.adafruit.com › using-python-on-windows-10 › command-line-python
Command Line Python | Using Python on Windows 10 | Adafruit Learning System
June 3, 2019 - Scroll the left side all the way down to Windows System - click the icon and sub menu items pop in, select Command Prompt with the black icon. Unlike the Python app noted in the previous page, the Command Prompt does not put you in a REPL or IDLE.
🌐
YouTube
youtube.com › shorts › efQCL9Cogxw
How to check where Python is installed in Windows? where command in cmd #shorts #python - YouTube
March 24, 2024 - This short video shows how you can find the Python location on your Windows computer. It uses a simple command called the "where" command. We just write wher...
🌐
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?

Find elsewhere
Top answer
1 of 16
234

You need to add C:\Python27 to your system PATH variable, not a new variable named "python".

Find the system PATH environment variable, and append to it a ; (which is the delimiter) and the path to the directory containing python.exe (e.g. C:\Python27). See below for exact steps.

The PATH environment variable lists all the locations that Windows (and cmd.exe) will check when given the name of a command, e.g. "python" (it also uses the PATHEXT variable for a list of executable file extensions to try). The first executable file it finds on the PATH with that name is the one it starts.

Note that after changing this variable, there is no need to restart Windows, but only new instances of cmd.exe will have the updated PATH. You can type set PATH at the command prompt to see what the current value is.


Exact steps for adding Python to the path on Windows 7+:

  1. Computer -> System Properties (or Win+Break) -> Advanced System Settings
  2. Click the Environment variables... button (in the Advanced tab)
  3. Edit PATH and append ;C:\Python27 to the end (substitute your Python version)
  4. Click OK. Note that changes to the PATH are only reflected in command prompts opened after the change took place.
2 of 16
66

Assuming you have Python2.7 installed

  1. Goto the Start Menu

  2. Right Click "Computer"

  3. Select "Properties"

  4. A dialog should pop up with a link on the left called "Advanced system settings". Click it.

  5. In the System Properties dialog, click the button called "Environment Variables".

  6. In the Environment Variables dialog look for "Path" under the System Variables window.

  7. Add ";C:\Python27" to the end of it. The semicolon is the path separator on windows.

  8. Click Ok and close the dialogs.

  9. Now open up a new command prompt and type "python"

It should work.

🌐
GeeksforGeeks
geeksforgeeks.org › how-to-set-up-command-prompt-for-python-in-windows10
How to set up Command Prompt for Python in Windows10 ? - GeeksforGeeks
August 28, 2020 - Step 5: Now go to the windows search bar and search for “Environment variables” and open it. ... In the “Edit System Variable” menu click on “new”, then paste the file location you copied and click ok. Now close the Environment menus by clicking ok and congratulation, we have set up the Command Prompt for python.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-use-cmd-for-python-in-windows-10
How to use CMD for Python in Windows 10 - GeeksforGeeks
July 15, 2025 - Now go to the Windows search bar and search for "Environment variables" and open it. ... In the "Edit System Variable" menu click on "new", then paste the file location you copied and click ok.
🌐
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.
🌐
pythontutorials
pythontutorials.net › blog › how-can-i-find-where-python-is-installed-on-windows
How to Find Where Python is Installed on Windows: Step-by-Step Guide to Locate Python Installation Path — pythontutorials.net
CommandType Name Version Source ----------- ---- ------- ------ Application python.exe 3.9.0.0 C:\Users\YourName\AppData\Local\Programs\Python\Python39\python.exe · The Source field shows the full path to python.exe. ... If you installed Python via the Microsoft Store or the official installer, Windows Settings can help locate it.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to find path where python is installed on windows?
How to Find Path Where Python is Installed on Windows? - Be on the Right Side of Change
June 23, 2021 - Alternatively, you can check your Python installation path in your Windows command-line by using the simple two-word command “where Python“. Here’s how this works on my Windows machine:
Top answer
1 of 2
1

Given that you're most familiar with Unix, I'm not sure if you are comfortable with Regedit and the Windows registry.

So let's get you a simple well-regarded tool to handle this task without asking you to manually edit the Windows registry.

First download FileTypesMan from NirSoft. It's written by Nir Sofer, who is a well-known and trusted developer. It's not open-source (unfortunately), but Nir has been publishing free tools for over 15 years with an unblemished record.

Now follow these simple steps within FileTypesMan:

  1. Find the .py file type in the top pane and click on it.
  2. In the bottom pane, find the open action (Name column) and double-click it.
  3. In the ensuing dialog box, change the command line to "C:\Windows\py.exe" "%1"
  4. In that same dialog box, ensure the Default Action checkbox is checked and the Disabled checkbox is not checked, then click OK to close the dialog box.

Voilà. You're done.

You can now close FileTypesMan.

Depending on the installed version of Windows, you may need to restart the shell. If you don't know how to do that programmatically, just log off, and log back in. Or, if you prefer, reboot.

As Gerhard mentioned in the comments, there is a significant security risk to allowing scripts to run directly like this, but you mentioned you understand the risks and the tradeoffs are worth it to you. I simply recap those comments here in this answer to help people in the future in the event that the comments get deleted.

2 of 2
1

...I want to just type "blah" to execute blah.py
- You can try:

1. Add the path to the Python.exe binary

2. Add eXtensions .py and .pyw to the PathExt variable

3. Run your files

> Your_py_Script
> Your_pyw_Script

  • How to set the Path and environment variables in Windows
  • What is the PathExt Environment Variable in Windows?
🌐
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 - C:\Users\SHREYA\AppData\Local\Programs\Python\Python311\python.exe C:\Users\SHREYA\AppData\Local\Microsoft\WindowsApps\python.exe ... There is another way to locate your Python installation files using the command line.
🌐
Codemia
codemia.io › home › knowledge hub › how can i find where python is installed on windows?
How can I find where Python is installed on Windows? | Codemia
September 23, 2025 - On Windows, the right way to find Python depends on whether you want the executable currently on your PATH, the interpreter launched by the Python Launcher, or the full installation directory of a specific environment. The most reliable commands are usually where python, py -0p, and python -c ...
🌐
Reddit
reddit.com › r/learnprogramming › how do you *actually* use python on your computer?
r/learnprogramming on Reddit: How do you *actually* use python on your computer?
February 22, 2020 -

I took an intro to python class, and I don’t understand even just the basics of this. Like, do you open a window, type in the code, and then press a button? Like, if I want to write a program, what applications am I using?

Thanks 🙏

🌐
Python
docs.python.org › 3 › faq › windows.html
Python on Windows FAQ — Python 3.14.6 documentation
Many people use the interactive mode as a convenient yet highly programmable calculator. When you want to end your interactive Python session, call the exit() function or hold the Ctrl key down while you enter a Z, then hit the “Enter” key to get back to your Windows command prompt.