【问题标题】:Process.start is finding the wrong python versionProcess.start 正在查找错误的 python 版本
【发布时间】:2014-08-13 15:44:38
【问题描述】:

我有以下

protected void RunPython(string scriptname)
{
    var p = new Process();
    p.StartInfo.FileName = @"python";
    p.StartInfo.Arguments = scriptname;
    p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    p.StartInfo.UseShellExecute = true;
    p.Start();
    Assert.True(p.WaitForExit(10000));
}

当我调用它时(当前从 VS 调试构建),它调用 python 2.2..(我安装了 2.2、2.6、2.7、3.3 和 3.4)

在我的 PATH 中只有 3.4。如果我从命令提示符调用“python --version”或“Python.exe --version”,它会告诉我我使用的是 3.4

.Net 在哪里找到 2.2? / 我该如何阻止它?

编辑:添加

PATH (User): C:\Tcl\bin;C:\Users\[UserName]\AppData\Roaming\npm;%PATH%;C:\Program Files (x86)\Nmap
PATH (System): C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\TortoiseGit\bin;C:\Program Files\PostgreSQL\9.3\bin;C:\Python34;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Vim\vim74;C:\Program Files\TortoiseSVN\bin

谢谢

【问题讨论】:

  • 请张贴您的整个路径,以及它可能包含的所有标点符号。你是从命令行开始,还是从 VS 开始?
  • 我会完全限定 Python 的位置以避免这个问题。一般来说,像这样依赖于系统变量并不是很健壮,因为用户可能会通过更新PATH 变量来意外破坏您的系统。
  • 问题是这是在一个测试套件中。它需要在所有开发人员机器和基于 debian/mono 的测试服务器上运行。
  • 您可以使用自己的环境变量,而不是路径。说,@"%test_python%\\python"
  • 发现问题 - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe 下的注册表项

标签: c# .net exec


【解决方案1】:

发现问题

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe

Appears Process 不知道 PATH,或者如果它知道,它会辅助使用它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    相关资源
    最近更新 更多