Running python scripts with subprocess in windows.

2019-02-20 22:16发布

问题:

So i'm trying to setup the python code checkers suggested in the emacs wiki. However, I'm unable to run those scripts in my command shell let alone emacs. The section is found here: http://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc7 And I tried the script located here and here

In both cases I changed the first line from #!usr/bin python with the full path of my python executable and when I run the scripts via

python pylint_etc_wrappers.py someModule.py 

or

python pycheckers.py soemModule.py

both boil down to the same error, most likely because they try to open a subprocess. Here's the trace:

Traceback (most recent call last):
  File "pycheckers.py", line 254, in <module>
    runner.run(source_file)
  File "pycheckers.py", line 91, in run
    process = Popen(args, stdout=PIPE, stderr=PIPE)
  File "C:\devel\Python\Python-2.7\Lib\subprocess.py", line 672, in __init__
    errread, errwrite)
  File "C:\devel\Python\Python-2.7\Lib\subprocess.py", line 882, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

The second script suggests to change the first line to the path of the interpreter (which I did) and to change the path in the main function which looks something like :

os.environ['PATH'] = \
      path.dirname(sys.executable) + ':' + os.environ['PATH']

which was a bit unclear to me. Any ideas?

回答1:

I have pylint 0.25.1, installed using easy_install (Python 2.7, Win XP). Both pylint and pylint.bat were installed in Python27/Scripts (this directory is in my PATH).

I too get the "The system cannot find the file specified" error when running the pylint_etc_wrapper.py script unchanged.

Running pylint from the script does work if

command = 'pylint'

is changed to

command = 'pylint.bat'

Another way to make it work is to add shell=True to the Popen() call.

I can't really explain all this, but there is an unresolved Python bug that looks like it might be relevant: http://bugs.python.org/issue8557.