我已成功安装virtualenv
并virtualenvwrapper
在我的系统上。它运行良好。为了将来的方便,我想创建一个脚本,将我喜欢的所有模块安装到我命名的环境pynumeric
中,位于~/.virtualenvs
. 对于这个脚本,我需要在virtualenvwrapper
我的脚本中使用。不幸的是,这对我不起作用。我不断收到不存在workon
的错误。mkvirtualenv
所以基本上我的问题归结为:为什么virtualenvwrapper
在终端而不是在我的 Python 脚本中工作?
install_pynumeric.py(编辑)
#!/usr/bin/python
import os
import sys
import subprocess as sp
# Set CPU frequency governer to performance
#sp.check_call('cpuset gov performance', shell=True)
# Check for parent directory of virtual environments
if not os.path.isdir('/home/carlos/.virtualenvs'):
sys.exit('The parent directory for virtual environments does not exist yet. Create it before preceeding.')
# Create virtual environment pynumeric if it does not exist yet and activate
if not os.path.isdir('/home/carlos/.virtualenvs/pynumeric'):
sp.check_call('mkvirtualenv pynumeric', shell=True)
# Activate pynumeric
sp.check_call('workon pynumeric', shell=True)
# List of Python modules to be installed
modules = ['numpy',
'scipy',
'sympy',
'matplotlib',
'pyqt4',
'sphinx',
'rope',
'pyflakes',
'ipython',
'pylint',
'psutil',
'spyder',
'pydstool'
]
# Install modules
for m in modules:
cmd = 'pip install ' + m
sp.check_call(cmd, shell=True)
# Deactivate pynumeric
sp.check_call('deactivate', shell=True)
# Set CPU frequency governer to ondemand
#sp.check_call('cpuset gov ondemand', shell=True)
我现在收到以下错误:
/bin/sh: mkvirtualenv: command not found
Traceback (most recent call last):
File "./install_pynumeric.py", line 16, in <module>
sp.check_call('mkvirtualenv pynumeric', shell=True)
File "/usr/lib/python2.7/subprocess.py", line 542, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'mkvirtualenv pynumeric' returned non-zero exit status 127