Windows normally installs Python on one of the two locations:
For me, it’s the latter. For you, it may be different—this article shows you how to check for yourself! 🙂
For your convenience, I’ve made a short gif that shows how I rushed through the code on my Windows machine:
Before you start, you may want to ask yourself the following question:
- Do you have access to a Python interpreter/shell?
- Do you have access to the command-line or PowerShell?
- Do you have neither?
Do You Have Access to a Python Shell?
To get the installation path in a human-readable format, run the following two lines in your Python shell:
- Import the
syslibraries with the command:
import os, sys
- Print the path to the shell using the command:
This is shown in the following code snippet:
import os, sys print(os.path.dirname(sys.executable))
The output on my computer is the following installation path:
You can copy it to the clipboard and use it wherever you need it.
An alternative way is shorter but generates an output that is less desirable with double front-slash path delimiters:
You can see the output in a Python shell on my computer:
import sys print(sys.executable) 'C:\\Users\\xcent\\AppData\\Local\\Programs\\Python\\Python39\\pythonw.exe'
Do You Have Access to the Command-Line or Powershell?
To get the Python installation path under Windows using the command line or PowerShell, you can pack the Python code in a concise and easy-to-copy one-liner command:
python -c "import os, sys; print(os.path.dirname(sys.executable))"
If Python is regularly installed, you can run the
python command from any directory in your PowerShell which makes it extra convenient.
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:
This gives me the following output:
You’ll learn an additional trick next that allows you to check your Python installation path without access to the Python interpreter or the windows command line.
But before we move on, I’m excited to present you my new Python book Python One-Liners (Amazon Link).
If you like one-liners, you’ll LOVE the book. It’ll teach you everything there is to know about a single line of Python code. But it’s also an introduction to computer science, data science, machine learning, and algorithms. The universe in a single line of Python!
The book was released in 2020 with the world-class programming book publisher NoStarch Press (San Francisco).
Get Python Installation Path Without Shell
To get the Python installation path on Windows without using either the Python interpreter or the command line, check the Windows registry that contains a key for each installed Python version. Both variants are possible:
If you have a 64-bit Windows version, you can find the Python path under the
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com. He’s author of the popular programming book Python One-Liners (NoStarch 2020), coauthor of the Coffee Break Python series of self-published books, computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.