通过os.system()激活virtualenv [英] Activate virtualenv via os.system()

查看:502
本文介绍了通过os.system()激活virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基于Python的shell脚本,使用virtualenv,pip和fabric来构造一个Django应用程序。应该是直截了当的,但似乎我无法通过shell脚本在virtualenv中激活和运行命令。

  os.system('virtualenv%s --no-site-packages'%project_name)
os.system('source%s / bin / activate'%project_name)
os.system('easy_install pip $)

运行时出现错误:

  $ startproject + -s false sample 
示例中的新的python可执行文件/ bin / python
安装setuptools ............完成。
/ testing
搜索pip
最佳匹配:pip 0.4
处理pip-0.4-py2.6.egg
pip 0.4已经是easy- install.pth
将脚本安装到/ usr / local / bin
错误:/ usr / local / bin / pip:Permission denied

显然,行没有运行,但为什么?这是一个并发/线程问题,还是使用virtualenv更深层次的问题?



谢谢!

解决方案

每个 os.system 调用创建一个新进程。您需要确保激活 easy_install 在相同的 os中运行.system subprocess call。


I'm writing a Python-based shell script to boilerplate a Django app with virtualenv, pip, and fabric. Should be straightforward enough, but it appears that I'm not able to activate and run commands in the virtualenv through the shell script.

os.system('virtualenv %s --no-site-packages' % project_name)
os.system('source %s/bin/activate' % project_name)
os.system('easy_install pip')

When running, this errors out:

$ startproject+ -s false sample
New python executable in sample/bin/python
Installing setuptools............done.
/testing
Searching for pip
Best match: pip 0.4
Processing pip-0.4-py2.6.egg
pip 0.4 is already the active version in easy-install.pth
Installing pip script to /usr/local/bin
error: /usr/local/bin/pip: Permission denied

Obviously the source line isn't being run, but why? Is it a concurrency/threading issue, or something deeper with virtualenv?

Thanks!

解决方案

Each os.system call creates a new process. You'll need to ensure that the activate and the easy_install are run in the same os.system or subprocess call.

这篇关于通过os.system()激活virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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