在Windows中使用subprocess运行Python脚本,来自emacswiki的Python代码检查器包装产生相同错误
我正在尝试设置一些在emacs wiki上推荐的Python代码检查工具。不过,我在命令行中无法运行这些脚本,更别提在emacs里了。
相关内容可以在这里找到:http://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc7。我尝试了这个脚本:这里和这里。
在这两个情况下,我把第一行从 #!usr/bin python 改成了我Python可执行文件的完整路径,然后通过
python pylint_etc_wrappers.py someModule.py
或者
python pycheckers.py soemModule.py
运行这些脚本,结果都出现了同样的错误,可能是因为它们试图打开一个子进程。以下是错误信息:
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
第二个脚本建议将第一行改成解释器的路径(我已经改了),还建议在主函数中更改路径,主函数的样子大概是:
os.environ['PATH'] = \
path.dirname(sys.executable) + ':' + os.environ['PATH']
这让我有点困惑。有没有什么建议?
1 个回答
1
我安装了pylint 0.25.1,是通过easy_install安装的(Python 2.7,Win XP)。pylint和pylint.bat都被放在了Python27/Scripts这个文件夹里(这个文件夹在我的PATH环境变量中)。
当我运行pylint_etc_wrapper.py这个脚本时,没做任何修改,也会出现“系统找不到指定的文件”的错误。
如果把运行pylint的部分改成
command = 'pylint'
就可以正常工作了。
command = 'pylint.bat'
另外一种解决方法是,在调用Popen()
时加上shell=True
。
我也说不清楚这些具体是怎么回事,但有一个未解决的Python bug,看起来可能和这个问题有关:http://bugs.python.org/issue8557。