作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试运行 virtualenvwrapper.sh
命令(即:lsvirtualenv 和 mkvirtualenv)。
我尝试使用
subprocess.call(["lsvirtualenv"])
但是好像不行。它给我以下错误消息:
Traceback (most recent call last):
File "importMaster.py", line 6, in <module>
virtualEnvs = subprocess.call(["lsvirtualenv"])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
由于这些函数位于 virtualenvwrapper.sh
文件中,我该如何在 python 脚本中引用该函数?
TIA
最佳答案
您需要使用 source $(which virtualenvwrapper.sh) && <your command>
与 shell=True
.
示例:
>>> from __future__ import print_function
>>> from subprocess import Popen, PIPE
>>> p = Popen("source $(which virtualenvwrapper.sh) && lsvirtualenv", shell=True, stdout=PIPE)
>>> print(p.stdout.read())
10leds
======
ambientlight
============
请参阅 Popen Constructor 的文档.
关于python - 我将如何通过 python 脚本运行 lsvirtualenv 或任何其他 virtualenvwrapper 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25024874/
我想知道我的机器上有多少个虚拟环境,我运行了: lsvirtualenv 但是收到错误信息: -bash: lsvirtualenv: command not found 我没有使用 anaconda
我正在尝试运行 virtualenvwrapper.sh 命令(即:lsvirtualenv 和 mkvirtualenv)。 我尝试使用 subprocess.call(["lsvirtualenv
我是一名优秀的程序员,十分优秀!