我将如何通过 python 脚本运行 lsvirtualenv 或任何其他 virtualenvwrapper 函数? [英] How would I run lsvirtualenv or any of the other virtualenvwrapper functions via python script?

查看:53
本文介绍了我将如何通过 python 脚本运行 lsvirtualenv 或任何其他 virtualenvwrapper 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行 virtualenvwrapper.sh 命令(即:lsvirtualenv 和 mkvirtualenv).

我尝试使用

subprocess.call(["lsvirtualenv"])

但它似乎不起作用.它给了我以下错误消息:

回溯(最近一次调用最后一次):文件importMaster.py",第 6 行,在 <module> 中virtualEnvs = subprocess.call(["lsvirtualenv"])文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",第 524 行,调用中返回 Popen(*popenargs, **kwargs).wait()文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",第 711 行,在 __init__ 中错误读取,错误写入)文件/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py",第 1308 行,在 _execute_child引发 child_exceptionOSError: [Errno 2] 没有那个文件或目录

由于这些函数位于 virtualenvwrapper.sh 文件中,我将如何在 python 脚本中引用该函数?

TIA

解决方案

你需要使用 source $(which virtualenvwrapper.sh) &&shell=True 中的 shell=True.

示例:

<预><代码>>>>从 __future__ 导入 print_function>>>从子流程导入 Popen, PIPE>>>p = Popen("source $(which virtualenvwrapper.sh) && lsvirtualenv", shell=True, stdout=PIPE)>>>打印(p.stdout.read())10颗======环境光============

请参阅 Popen Constructor 的文档.>

I'm attempting to run virtualenvwrapper.sh commands (ie: lsvirtualenv and mkvirtualenv).

I attempted to use

subprocess.call(["lsvirtualenv"])

but it does not seem to work. It gives me the following error message:

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

Since these functions are inside of the virtualenvwrapper.sh file, how would I go about referencing the function in a python script?

TIA

解决方案

You need to use source $(which virtualenvwrapper.sh) && <your command> with shell=True.

Example:

>>> 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
============

See the documentation for the Popen Constructor.

这篇关于我将如何通过 python 脚本运行 lsvirtualenv 或任何其他 virtualenvwrapper 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆