404

I want to find out my Python installation path on Windows. For example:

C:\Python25

How can I find where Python is installed?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Fang-Pen Lin
  • 13,420
  • 15
  • 66
  • 96
  • You should give more information. You know that Python is installed, but can you run Python or not? In my case, I didn't install it; various products may have installed it and I want to find out if it exists somewhere in the file system. Would the interpreter be called python.exe? I have no idea. – David Spector Nov 30 '19 at 02:25

23 Answers23

731

In your Python interpreter, type the following commands:

>>> import os
>>> import 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))"
Mrityunjai
  • 163
  • 2
  • 8
elo80ka
  • 14,837
  • 3
  • 36
  • 43
  • 2
    What if you're inside a virtualenv? This won't work then. – flaviut Oct 26 '17 at 18:14
  • 3
    @user60561 It should give you the path to the Virtualenv's Python executable. I don't know a way to get the OS python, in that case, but I'd be interested to know why you'd need that, if you were running from within a Virtualenv? – elo80ka Oct 28 '17 at 14:23
  • 1
    My script creates a virtualenv, so it uses the system python to do that. You've gotten me thinking though, maybe that's not necessary… I'll check it out on Monday, thank you! – flaviut Oct 28 '17 at 15:33
  • Error: "C:\WINDOWS\system32>import os 'import' is not recognized as an internal or external command, operable program or batch file." – David Spector Nov 25 '19 at 21:40
  • @David Spector: My bad. I should have noted that you have to type those commands in the Python interpreter, I'll update the answer :-) – elo80ka Nov 29 '19 at 14:02
  • @elo80ka that explains it, thanks. If I don't know where python is installed, how can I run the interpreter? I should explain: many products for Windows use the Python interpreter, so it must be installed somewhere. I'd like to find it so I can use it and so it can possibly be shared. I'm not sure my situation is the same as the OP's. – David Spector Nov 30 '19 at 02:21
  • You should enter print(...) so that it displays with only a single backslash and not the raw string. `print(os.path.dirname(sys.executable))` – Steven Apr 18 '20 at 16:15
  • This is exactly what I was looking for. My issue / reason I had a hard time finding this is because it was located in C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64 – Mifo Jul 24 '20 at 16:33
  • @elo80ka How would you enter this command in Virtual Studio Code? I tried doing it the exact way you typed it, but it didn't recognize the command. Also, when I tried using the cmd solution cmd said it couldn't find Python, even though I know I have it installed. – DualBall Jun 14 '21 at 16:26
  • @DualBall you're supposed to type those in either the Python interactive prompt (first example), or your terminal. You can use the built-in terminal in VSCode. – elo80ka Jun 15 '21 at 21:45
  • This only works if you can find the interpreter in your program menu. I just installed python and the icons are not there. – posfan12 Jun 18 '21 at 15:46
  • @elo80ka Ah, I see what you mean now. Didn't know I was supposed to use the second example in vs code as well as cmd; I tried using the first example for vs code. Still, when I run the command in the terminal, it insists on telling me "Python not found", just like cmd does. How do I resolve this when I already have Python installed? – DualBall Jun 19 '21 at 17:53
  • @user60561 I found myself in a similar situation and ended up using `os.environ['PATH']`. This returns a semicolon-separated string. I then parse it to find the Python path. Bit hacky but it's able to find the system interpreter location instead of the virtual environment one. – investigate311 May 19 '22 at 00:38
234

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 :

enter image description here

Aekansh Kansal
  • 2,799
  • 1
  • 15
  • 17
103

It would be either of

  • C:\Python36
  • C:\Users\(Your logged in User)\AppData\Local\Programs\Python\Python36
Amol Manthalkar
  • 1,890
  • 2
  • 16
  • 16
  • 8
    my path of python 3.6 on win10: `C:\Users\YANG.LEI\AppData\Local\Programs\Python\Python36-32` – Lei Yang Dec 27 '17 at 09:23
  • 12
    The Python path can be customized freely during the installation. I had several machines that didn't even *have* a c:\ drive. Also, the local application data isn't necessarily under `C:\Users`. – Matteo Italia Apr 11 '18 at 13:10
  • 2
    This is not correct and it can be installed anywhere. elo80ka's answer is the one to use! – Hossein Sep 29 '20 at 09:36
  • 1
    This worked for me. If you don't know where the python interpreter is and it's not in the path, how can you follow the instructions from @Hossein??? – Scott Siddall Oct 22 '21 at 12:15
  • @ScottSiddall so you are saying, you know Python is installed on your machine, but its not in PATH, you need to find it somehow! there are many ways, one would be to use the good old search in windows, or use Everything! or open up regedit and search for python. you'll find what you were looking for. – Hossein Oct 22 '21 at 12:27
54

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\InstallPath
  • HKCU\SOFTWARE\Python\PythonCore\versionnumber\InstallPath

In 64-bit Windows, it will be under the Wow6432Node key:

  • HKLM\SOFTWARE\Wow6432Node\Python\PythonCore\versionnumber\InstallPath
yincrash
  • 6,394
  • 1
  • 39
  • 41
codeape
  • 97,830
  • 24
  • 159
  • 188
  • this seems to be false on windows 7, at least for python 2.7 – sharkin Dec 09 '10 at 12:08
  • Where's the info located on windows 7? If you have a Windows 7 computer handy, could you do a registry search for Python and PythonCore? And see if you find a InstallPath value somewhere. – codeape Dec 09 '10 at 14:30
  • 7
    In 64-bit versions of windows (which you are probably using) it will be under the Wow6432Node key, IE HKLM\SOFTWARE\Wow6432Node\Python\PythonCore\versionnumber\InstallPath – piksel bitworks Sep 23 '13 at 06:51
  • Please update your answer with 'piksel bitworks's comment. It worked for me. – dinesh ygv Jun 01 '14 at 08:23
  • 1
    It's a nice way but to use it one needs to know the current python version. I'm still looking for a good way to detect the python path for use with nsis installer. – PerryWerneck Nov 09 '15 at 17:20
  • 1
    It's under Wow6432Node if it's 32-bit python on 64-bit windows. Note also that a 32-bit app cannot normally detect the 64-bit (non-Wow6432Node) keys in the registry because of registry redirection (which means 64-bit python install wouldn't be detected by a 32-bit app). – jtbr Feb 09 '18 at 12:40
  • 1
    Arrgghh. I wasn't paying attention on install and they put it off the root. Why is it so hard to get with the program and put it in the correct hierarchy? – GaTechThomas Apr 01 '18 at 22:11
  • No "pythoncore" anywhere in my Registry. But several of my programs use python. Must be a way to search the file system for some unique filename for the interpreter. – David Spector Nov 25 '19 at 21:43
38

Simple way is

  1. open CMD
  2. type where python in cmd
BigData-Guru
  • 1,161
  • 1
  • 15
  • 20
28

If you have the py command installed, which you likely do, then just use the --list-paths/-0p 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.

carlin.scott
  • 6,214
  • 3
  • 30
  • 35
24

On my windows installation, I get these results:

>>> import sys
>>> sys.executable
'C:\\Python26\\python.exe'
>>> sys.platform
'win32'
>>>

(You can also look in sys.path for reasonable locations.)

gimel
  • 83,368
  • 10
  • 76
  • 104
16

Its generally

'C:\Users\user-name\AppData\Local\Programs\Python\Python-version'

or try using (in cmd )

where python

utkarsh2299
  • 161
  • 1
  • 3
12

In 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))
Guðmundur H
  • 11,478
  • 3
  • 24
  • 22
10

If You want the Path After successful installation then first open you CMD and type python or python -i

It Will Open interactive shell for You and Then type

import sys

sys.executable

Hit enter and you will get path where your python is installed ...

Community
  • 1
  • 1
  • The problem I had with this solution is that I was running python 2.7 and wanted to upgrade to 3.6. I installed 3.6 but when I type python on the command line I was running from the old 2.7 still. – tzg Nov 14 '18 at 15:22
8

To know where Python is installed you can execute where python in your cmd.exe.

anothernode
  • 5,100
  • 13
  • 43
  • 62
  • (This post does not seem to provide an [answer](https://stackoverflow.com/help/how-to-answer) to the question. Please either edit your answer, or just post it as a comment to the question). – sɐunıɔןɐqɐp Jul 27 '18 at 06:44
  • 2
    @sɐunıɔןɐqɐp It actually is an answer and it might even be correct. I'm not very familiar with Windows, but there in fact [seems to be a `where` command](https://stackoverflow.com/questions/304319/is-there-an-equivalent-of-which-on-the-windows-command-line) which is supposed to be similar to `which` on Unixes. – anothernode Jul 27 '18 at 07:23
  • @anothernode: The answer's quality is very bad. In case you understand what the author is trying to say, you are free to edit and fix it. – sɐunıɔןɐqɐp Jul 27 '18 at 07:26
  • 1
    the answer's quality is not bad, the question's quality is. I can confirm ```where python``` works on cmd.exe – Kay Mar 02 '20 at 14:56
6

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.

Amit Gupta
  • 2,698
  • 4
  • 24
  • 37
6

Make use of the Python Launcher for Windows (available as of 3.3). It is compatible with all available versions of python.

First, check if the launcher is available:

py 

starts the latest installed version of Python

To see all Python versions available on your system and their path:

py -0p

or

py --list-paths

For a specific Python version path—especially useful with multiple python installations:

py -3.7 -c "import os, sys; print(os.path.dirname(sys.executable))"

python 2

py -2 -c "import os, sys; print(os.path.dirname(sys.executable))"

py installed location is C:\Windows\py.exe if installed for all users, otherwise can be found at C:\Users\username\AppData\Local\Programs\Python\Launcher. It does not require the environment PATH variable to be set if installed for all users.

oyeyipo
  • 359
  • 3
  • 11
4

You can find it in the Windows GUI, but you need to select “show hidden” in the menu. Directory where python is installed on my Win10 computer:

C:\Users\username\AppData\Local\Programs\Python\Python310

Very handy if you use python pip to install packages.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • I will note that for those that are trying to do a "Get-Command python" or a "where python" you might well get something like "C:\Users\username\AppData\Local\Microsoft\WindowsApps\python.exe" which seems to be some sort of link, but not one that gci will give up the target of. Which is frustrating for what should be obvious reasons. – Dweeberly Mar 15 '23 at 23:53
3

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");
}
Peter
  • 37,042
  • 39
  • 142
  • 198
2

This worked for me: C:\Users\Your_user_name\AppData\Local\Programs\Python

My currently installed python version is 3.7.0

Hope this helps!

David
  • 1,192
  • 5
  • 13
  • 30
Prashant Gonga
  • 163
  • 2
  • 7
2

Go to C:\Users\USER\AppData\Local\Programs\Python\Python36 if it is not there then open console by windows+^R Then type cmd and hit enter type python if installed in your local file it will show you its version from there type the following import os import sys os.path.dirname(sys.executable)

2

You could have many versions of Python installed on your machine. So if you're in Windows at a command prompt, entering something like this...

py --version

...should tell you what version you're using at the moment. (Maybe replace py with python or python3 if py doesn't work). Anyway you'd see something like

Python 3.10.2

If you then create a virtual environment using something like this...

py -m venv venv

...that environment will also use that Python version. To verify, activate the environment...

venv\scripts\activate.bat 

You'll see the name of the command prompt. Now if execute:

where python

...it will show you which Python executable that virtual environment uses. It will be a copy of Python.exe what's actually in the Scripts subfolder of the virtual environment folder. Of course to see which version that is, again use py --version.

Alan Simpson
  • 447
  • 5
  • 5
0

if you still stuck or you get this

C:\\\Users\\\name of your\\\AppData\\\Local\\\Programs\\\Python\\\Python36

simply do this replace 2 \ with one

C:\Users\akshay\AppData\Local\Programs\Python\Python36
Kos
  • 4,890
  • 9
  • 38
  • 42
0

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

0

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.

PV8
  • 5,799
  • 7
  • 43
  • 87
0

Option 1 : Check System Environment Variables > Path

Option 2 : C:\Users\Asus\AppData\Local\Programs\Python (By default Path)

0

On my Windows 11, I have two Python installed: 3.11.2 and 3.8. The below commends give only one of them.

Which python

which py

To find out the location of both the below Powershell commands come in handy:

$User = New-Object System.Security.Principal.NTAccount($env:UserName)

$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value

New-PSDrive HKU Registry HKEY_USERS

Get-ChildItem "HKU:\${sid}\Software\Python\PythonCore\*\InstallPath"