255

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

C:\Python25

How can I find where Python is installed?

Stevoisiak
  • 16,510
  • 19
  • 94
  • 173
Fang-Pen Lin
  • 10,892
  • 13
  • 59
  • 90
  • 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

18 Answers18

474

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
  • 123
  • 2
  • 8
elo80ka
  • 11,979
  • 3
  • 33
  • 43
  • What if you're inside a virtualenv? This won't work then. – user60561 Oct 26 '17 at 18:14
  • 1
    @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
  • 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! – user60561 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
111

If you have Python in your environment variable then you can use the following command in cmd:

 where python

or for Unix enviroment

 which python

command line image :

enter image description here

Jin Lee
  • 2,245
  • 10
  • 23
  • 58
Aekansh Kansal
  • 1,391
  • 1
  • 10
  • 13
63

It would be either of

  • C:\Python36
  • C:\Users\(Your logged in User)\AppData\Local\Programs\Python\Python36
Amol Manthalkar
  • 1,442
  • 1
  • 14
  • 15
  • 3
    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
  • 9
    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
  • 1
    This is not correct and it can be installed anywhere. elo80ka's answer is the one to use! – Rika Sep 29 '20 at 09:36
50

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
  • 5,746
  • 1
  • 36
  • 38
codeape
  • 89,707
  • 22
  • 139
  • 171
  • 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
16

Simple way is

1) open CMD
2) type >>where python
BigData-Guru
  • 667
  • 1
  • 6
  • 17
15

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
  • 73,814
  • 10
  • 69
  • 104
12

Its generally

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

or try using (in cmd )

where python

utkarsh2299
  • 121
  • 1
  • 2
10

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.

carlin.scott
  • 3,719
  • 2
  • 19
  • 27
10

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
  • 9,428
  • 3
  • 21
  • 22
8

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
6

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

anothernode
  • 4,369
  • 11
  • 37
  • 53
  • (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
5

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
  • 1,636
  • 1
  • 17
  • 30
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
  • 33,550
  • 33
  • 138
  • 185
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)

1

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,050
  • 1
  • 13
  • 27
Prashant Gonga
  • 153
  • 1
  • 6
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
  • 3,847
  • 8
  • 29
  • 34
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
  • 4,547
  • 3
  • 24
  • 52