我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到Python的安装位置?
我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到Python的安装位置?
当前回答
我安装了2和3,也遇到了同样的问题。幸运的是,在windows路径中输入path让我找到了安装它的位置。这个路径是我安装Python时的一个选项,只是我忘记了。如果你在安装Python 3时没有选择设置路径,这可能无法工作-除非你在安装时手动更新了路径。 对我来说,是在c:\Program Files\Python37\python.exe
其他回答
在我的windows安装,我得到这些结果:
>>> import sys
>>> sys.executable
'C:\\Python26\\python.exe'
>>> sys.platform
'win32'
>>>
(你也可以在sys。合理位置的路径)
如果你还是卡住了,或者你会得到这个
C:\\\Users\\\name of your\\\AppData\\\Local\\\Programs\\\Python\\\Python36
简单地把2 \换成1
C:\Users\akshay\AppData\Local\Programs\Python\Python36
两者都有可能
C: \ Python36 C:\Users\(您登录的用户)\AppData\Local\Programs\Python\Python36
简单的方法是
打开CMD 在CMD中键入where python
如果有人需要在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");
}