【发布时间】:2020-12-15 15:21:57
【问题描述】:
我可以在 Windows 命令行中成功输入 SVN 命令,但是当我尝试通过带有 shell=True 的子进程传递它们时,我收到此错误:
'svn' 不是内部或外部命令、可运行程序或批处理文件
当我省略 shell 参数时,我得到这个:
WindowsError: [错误 2] 系统找不到指定的文件
我在 Windows 10 上运行 Python 2.7,我还安装了 Python 3.8。我尝试了各种 SVN 命令,有些复杂,有些简单,有各种参数,既作为单个字符串,也作为字符串列表,在 IDLE 和 Spyder 中(每个中都有控制台和脚本),并不断获得相同的结果。我能够通过子进程传递其他类型的 Windows 命令,而不是 SVN。我已经确认 COMSPEC 环境变量是正确的。我还尝试在 PATH 环境变量中将 svn.exe 的路径一直向上移动并重新启动。没有骰子。
这是我正在尝试做的一个示例:
import subprocess
my_cmd = ['svn', 'propget', 'svn:externals', '-R', '"https://the/rest/of/the/url"']
res = subprocess.check_output(my_cmd, shell=True)
print "the result of the svn command via subprocess is...\n{}".format(res)
【问题讨论】:
-
你能从命令窗口运行
svn吗? -
是的,我可以直接在那里输入 SVN 命令就好了(这就是我在文章开头试图传达的内容)。如果您的意思是在命令窗口中运行 Python 脚本,那么不 - 会产生相同的结果。谢谢。
-
也许更新的 PATH 变量没有被使用?向我们展示
import os; print(os.environ.get('PATH'))的输出 -
C:\Python2710\WinPython\179-2146-001\python-2.7.10.amd64\Lib\site-packages\PyQt5;C:\Python2710\WinPython\179-2146-001\ python-2.7.10.amd64\Lib\site-packages\PyQt4;C:\Python2710\WinPython\179-2146-001\python-2.7.10.amd64\;
-
C:\Python2710\WinPython\179-2146-001\python-2.7.10.amd64\DLLs;C:\Python2710\WinPython\179-2146-001\python-2.7.10。 amd64\Scripts;C:\Python2710\WinPython\179-2146-001\python-2.7.10.amd64\..\tools;C:\Python2710\WinPython\179-2146-001\python-2.7.10.amd64 \..\tools\mingw32\bin;C:\Python2710\WinPython\179-2146-001\python-2.7.10.amd64\..\tools\R\bin\x64;C:\Python2710\WinPython\179 -2146-001\python-2.7.10.amd64\..\tools\Julia\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Python2710\WinPython\179-2146-001\python-2.7 .10.amd64;
标签: python svn windows-10 subprocess