I want to find out my Python installation path on Windows. For example:
我想在Windows上找到我的Python安装路径。例如:
C:\Python25
How can I find where Python is installed?
如何找到Python的安装位置?
9 个解决方案
#1
136
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
#2
40
If you need to know the installed path under Windows without starting the python interpreter, have a look in the Windows registry.
如果您需要在不启动python解释器的情况下知道Windows下的已安装路径,请查看Windows注册表。
Each installed Python version will have a registry key in either:
每个安装的Python版本都有一个注册表项:
HKLM\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
- HKLM \ SOFTWARE \ Python的\ PythonCore \版本号\安装路径
HKCU\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
- HKCU \ SOFTWARE \ Python的\ PythonCore \版本号\安装路径
In 64-bit Windows, it will be under the Wow6432Node
key:
在64位Windows中,它将位于Wow6432Node键下:
HKLM\SOFTWARE\Wow6432Node\Python\PythonCore\versionnumber\InstallPath
- HKLM \ SOFTWARE \ Wow6432Node \ Python的\ PythonCore \版本号\安装路径
#3
16
It would be either of
它可能是
- C:\Python36
- C:\ Python36
- C:\Users\(Your logged in User)\AppData\Local\Programs\Python\Python36
- C:\ Users \(您登录的用户)\ AppData \ Local \ Programs \ Python \ Python36
#4
11
On my windows installation, I get these results:
在我的Windows安装上,我得到了这些结果:
>>> import sys
>>> sys.executable
'C:\\Python26\\python.exe'
>>> sys.platform
'win32'
>>>
(You can also look in sys.path
for reasonable locations.)
(您还可以在sys.path中查找合理的位置。)
#5
10
If you have python in your enviroment variable so you can also use type command in cmd as
如果你的环境变量中有python,那么你也可以在cmd中使用type命令
>>> where python
命令行图像
#6
8
In the sys
package, you can find a lot of useful information about your installation:
在sys包中,您可以找到许多有关安装的有用信息:
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.
我不确定这会给你的Windows系统带来什么,但是我的Mac可执行文件指向Python二进制文件,exec_prefix指向安装根目录。
You could also try this for inspecting your sys
module:
您也可以尝试这个来检查您的sys模块:
import sys
for k,v in sys.__dict__.items():
if not callable(v):
print "%20s: %s" % (k,repr(v))
#7
2
If anyone needs to do this in C# I'm using the following code:
如果有人需要在C#中执行此操作,我使用以下代码:
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");
}
#8
0
This worked for me: C:\Users\Your_user_name\AppData\Local\Programs\Python
这对我有用:C:\ Users \ Your_user_name \ AppData \ Local \ Programs \ Python
My currently installed python version
is 3.7.0
我目前安装的python版本是3.7.0
Hope this helps!
希望这可以帮助!
#9
-1
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
只需这样就可以用一个替换2 \
C:\Users\akshay\AppData\Local\Programs\Python\Python36
#1
136
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'
#2
40
If you need to know the installed path under Windows without starting the python interpreter, have a look in the Windows registry.
如果您需要在不启动python解释器的情况下知道Windows下的已安装路径,请查看Windows注册表。
Each installed Python version will have a registry key in either:
每个安装的Python版本都有一个注册表项:
HKLM\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
- HKLM \ SOFTWARE \ Python的\ PythonCore \版本号\安装路径
HKCU\SOFTWARE\Python\PythonCore\versionnumber\InstallPath
- HKCU \ SOFTWARE \ Python的\ PythonCore \版本号\安装路径
In 64-bit Windows, it will be under the Wow6432Node
key:
在64位Windows中,它将位于Wow6432Node键下:
HKLM\SOFTWARE\Wow6432Node\Python\PythonCore\versionnumber\InstallPath
- HKLM \ SOFTWARE \ Wow6432Node \ Python的\ PythonCore \版本号\安装路径
#3
16
It would be either of
它可能是
- C:\Python36
- C:\ Python36
- C:\Users\(Your logged in User)\AppData\Local\Programs\Python\Python36
- C:\ Users \(您登录的用户)\ AppData \ Local \ Programs \ Python \ Python36
#4
11
On my windows installation, I get these results:
在我的Windows安装上,我得到了这些结果:
>>> import sys
>>> sys.executable
'C:\\Python26\\python.exe'
>>> sys.platform
'win32'
>>>
(You can also look in sys.path
for reasonable locations.)
(您还可以在sys.path中查找合理的位置。)
#5
10
If you have python in your enviroment variable so you can also use type command in cmd as
如果你的环境变量中有python,那么你也可以在cmd中使用type命令
>>> where python
命令行图像
#6
8
In the sys
package, you can find a lot of useful information about your installation:
在sys包中,您可以找到许多有关安装的有用信息:
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.
我不确定这会给你的Windows系统带来什么,但是我的Mac可执行文件指向Python二进制文件,exec_prefix指向安装根目录。
You could also try this for inspecting your sys
module:
您也可以尝试这个来检查您的sys模块:
import sys
for k,v in sys.__dict__.items():
if not callable(v):
print "%20s: %s" % (k,repr(v))
#7
2
If anyone needs to do this in C# I'm using the following code:
如果有人需要在C#中执行此操作,我使用以下代码:
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");
}
#8
0
This worked for me: C:\Users\Your_user_name\AppData\Local\Programs\Python
这对我有用:C:\ Users \ Your_user_name \ AppData \ Local \ Programs \ Python
My currently installed python version
is 3.7.0
我目前安装的python版本是3.7.0
Hope this helps!
希望这可以帮助!
#9
-1
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
只需这样就可以用一个替换2 \
C:\Users\akshay\AppData\Local\Programs\Python\Python36