I want to find out my Python installation path on Windows. For example:
C:\Python25
How can I find where Python is installed?
I want to find out my Python installation path on Windows. For example:
C:\Python25
How can I find where Python is installed?
If you need to know the installed path under Windows without starting the python interpreter, have a look in the Windows registry.
Each installed Python version will have a registry key in either:
HKLM\SOFTWARE\Python\PythonCore\versionnumber\InstallPathHKCU\SOFTWARE\Python\PythonCore\versionnumber\InstallPathIn 64-bit Windows, it will be under the Wow6432Node key:
HKLM\SOFTWARE\Wow6432Node\Python\PythonCore\versionnumber\InstallPathIn the sys package, you can find a lot of useful information about your installation:
import sys
print sys.executable
print sys.exec_prefix
I'm not sure what this will give on your Windows system, but on my Mac executable points to the Python binary and exec_prefix to the installation root.
You could also try this for inspecting your sys module:
import sys
for k,v in sys.__dict__.items():
if not callable(v):
print "%20s: %s" % (k,repr(v))
If you have the py command installed, which you likely do, then just use the --list-paths argument to the command:
py --list-paths
Example output:
Installed Pythons found by py Launcher for Windows
-3.8-32 C:\Users\cscott\AppData\Local\Programs\Python\Python38-32\python.exe *
-2.7-64 C:\Python27\python.exe
The * indicates the currently active version for scripts executed using the py command.
You can search for the "environmental variable for you account". If you have added the Python in the path, it'll show as "path" in your environmental variable account.
but almost always you will find it in "C:\Users\%User_name%\AppData\Local\Programs\Python\Python_version"
the 'AppData' folder may be hidden, make it visible from the view section of toolbar.
If anyone needs to do this in C# I'm using the following code:
static string GetPythonExecutablePath(int major = 3)
{
var software = "SOFTWARE";
var key = Registry.CurrentUser.OpenSubKey(software);
if (key == null)
key = Registry.LocalMachine.OpenSubKey(software);
if (key == null)
return null;
var pythonCoreKey = key.OpenSubKey(@"Python\PythonCore");
if (pythonCoreKey == null)
pythonCoreKey = key.OpenSubKey(@"Wow6432Node\Python\PythonCore");
if (pythonCoreKey == null)
return null;
var pythonVersionRegex = new Regex("^" + major + @"\.(\d+)-(\d+)$");
var targetVersion = pythonCoreKey.GetSubKeyNames().
Select(n => pythonVersionRegex.Match(n)).
Where(m => m.Success).
OrderByDescending(m => int.Parse(m.Groups[1].Value)).
ThenByDescending(m => int.Parse(m.Groups[2].Value)).
Select(m => m.Groups[0].Value).First();
var installPathKey = pythonCoreKey.OpenSubKey(targetVersion + @"\InstallPath");
if (installPathKey == null)
return null;
return (string)installPathKey.GetValue("ExecutablePath");
}
I installed 2 and 3 and had the same problem finding 3. Fortunately, typing path at the windows path let me find where I had installed it. The path was an option when I installed Python which I just forgot. If you didn't select setting the path when you installed Python 3 that probably won't work - unless you manually updated the path when you installed it. In my case it was at c:\Program Files\Python37\python.exe
If you use anaconda navigator on windows, you can go too enviornments and scroll over the enviornments, the root enviorment will indicate where it is installed. It can help if you want to use this enviorment when you need to connect this to other applications, where you want to integrate some python code.