以下行引发了Linux中的奇怪异常(几个Ubuntu 14.04安装和一个安装了所有更新的Arch linux安装):
subprocess.call(['/home/vestnik/Development/test/python/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/venv/bin/pip','install','httpbin'])
python2.7:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
python3.5:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/subprocess.py", line 557, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/home/vestnik/Development/test/python/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/venv/bin/pip'
pip可执行文件我试图运行的是virtualenv bootstrap脚本创建的有效现有文件。当pip的路径长度变得大于120个字符(近似)时,会出现问题。如果我删除一个&#34; subdir&#34;路径中间的元素很有效。这个问题的原始来源是jenkins构建由于长工作空间名称而无法创建virtualenv。
子进程模块中的可执行路径长度是否存在任何限制(我还没有在函数文档中找到它),还是实现错误?有没有很好的方法来解决它?
答案 0 :(得分:0)
当我试图通过bash在venv中调用pip时,我的解释器出错了。
问题的真正根源是shebang字符串长度限制(对接受的答案here的评论声称默认限制等于127字节):
$ head -n1 /home/vestnik/Development/test/python/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/venv/bin/pip
#!/home/vestnik/Development/test/python/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/venv/bin/python3.5
$ head -n1 /home/vestnik/Development/test/python/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/subdir/venv/bin/pip | wc -c
129
问题源不是子进程模块。它只产生令人困惑的错误。
以下代码有效:
subprocess.call([
'/home/...lonl long venv path.../venv/bin/python3.5',
'/home/...lonl long venv path.../venv/bin/pip',
'install',
'httpbin'
])