我正在尝试使用python访问路径变量。
Subprocess.call& Subprocess.Popen似乎无法这样做,尽管Exe的位置在我的PATH变量中,并且可以从cmd.exe运行我也可以用可执行文件的绝对路径运行它,但这不是& #39; t理想。
管理找到这篇文章: Subprocess.call or Subprocess.Popen cannot use executables that are in PATH (Linux/Windows)
但他们解决环境变量并使用它们的解决方案并不适用于我。
import os
import subprocess
environment_vars = os.environ
input_image_location = 'D:/python/images/test_image.bmp'
output_image_location = 'D:/python/images/test_image_output.ps'
cmd_args = ["potrace", "-p", input_image_location, "-o",output_image_location]
proc = subprocess.Popen(cmd_args, env=environment_vars)
但这是错误的:
File "C:Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
有关如何使其发挥作用的任何提示?