我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到Python的安装位置?
我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到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");
}
其他回答
两者都有可能
C: \ Python36 C:\Users\(您登录的用户)\AppData\Local\Programs\Python\Python36
我安装了2和3,也遇到了同样的问题。幸运的是,在windows路径中输入path让我找到了安装它的位置。这个路径是我安装Python时的一个选项,只是我忘记了。如果你在安装Python 3时没有选择设置路径,这可能无法工作-除非你在安装时手动更新了路径。 对我来说,是在c:\Program Files\Python37\python.exe
选项1:检查系统环境变量>路径
选项2:C:\Users\Asus\AppData\Local\Programs\Python(默认路径)
如果你在windows上使用anaconda导航器,你可以去环境和滚动环境,根环境将指示它安装的位置。如果您需要将此环境连接到其他应用程序,并在其中集成一些python代码,则可以使用此环境。
使用Python Launcher for Windows(从3.3开始可用)。它与所有可用的python版本兼容。
首先,检查启动器是否可用:
py
启动最新安装的Python版本
查看系统上可用的所有Python版本及其路径:
py -0p
or
py --list-paths
对于特定的Python版本路径-对于多个Python安装尤其有用:
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))"
如果为所有用户安装,则安装位置为C:\Windows\py.exe,否则可以在c:\ users \username\ appdata \ local \ programs \ python \ launcher。 如果为所有用户安装,则不需要设置环境PATH变量。