1

I can enter SVN commands successfully in the Windows command line, but when I try to pass them via subprocess with shell=True I get this error:

'svn' is not recognized as an internal or external command, operable program or batch file

When I omit the shell argument I get this:

WindowsError: [Error 2] The system cannot find the file specified

I'm running Python 2.7 on Windows 10, where I also have Python 3.8 installed. I've tried a variety of SVN commands, some complex and some simple, with a variety of arguments, both as a single string and a list of strings, both in IDLE and Spyder (console and script in each), and keep getting the same results. I am able to pass other types of Windows commands via subprocess, just not SVN. I've confirmed that the COMSPEC environment variable is correct. I've also tried moving the path to svn.exe all the way up in the PATH environment variable and rebooting. No dice.

Here's an example of what I'm trying to do:

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)
10
  • Are you able to run svn from a command window? Commented Dec 15, 2020 at 15:24
  • Yeah, I can enter SVN commands directly there just fine (this is what I was trying to convey at the very beginning of my post). If you mean running the Python script in the command window, then no -- that yields the same result. Thanks. Commented Dec 15, 2020 at 16:14
  • Maybe the updated PATH variable isn't being used? Show us the output of import os; print(os.environ.get('PATH')) Commented Dec 15, 2020 at 16:17
  • 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\; Commented Dec 15, 2020 at 19:07
  • 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; Commented Dec 15, 2020 at 19:07

1 Answer 1

1

After finding that the path to svn.exe was missing from the string returned by os.environ.get('PATH'), I added this path with the following line:

os.environ['PATH'] += r"C:\Program Files\TortoiseSVN\bin;"

And now my subsequent SVN commands are working via subprocess.

Thank you @John Gordon and @Maurice Meyer for the help!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.