我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到Python的安装位置?
我想知道我在Windows上的Python安装路径。例如:
C:\Python25
如何找到Python的安装位置?
当前回答
C:\Users\Your_user_name\AppData\Local\Programs\Python
我目前安装的python版本是3.7.0
希望这能有所帮助!
其他回答
其一般
'C:\Users\user-name\AppData\Local\Programs\Python\Python-version'
或 尝试使用(在CMD中)
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");
}
选项1:检查系统环境变量>路径
选项2:C:\Users\Asus\AppData\Local\Programs\Python(默认路径)
在sys包中,你可以找到很多关于安装的有用信息:
import sys
print sys.executable
print sys.exec_prefix
我不确定这会在你的Windows系统上给出什么,但在我的Mac上,可执行文件指向Python二进制文件,exec_prefix指向安装根。
你也可以尝试检查你的sys模块:
import sys
for k,v in sys.__dict__.items():
if not callable(v):
print "%20s: %s" % (k,repr(v))
如果你在windows上使用anaconda导航器,你可以去环境和滚动环境,根环境将指示它安装的位置。如果您需要将此环境连接到其他应用程序,并在其中集成一些python代码,则可以使用此环境。