gpt4 book ai didi

python - 如何在 Python 脚本中使用 virtualenvwrapper

转载 作者:行者123 更新时间:2023-11-28 19:23:10 25 4
gpt4 key购买 nike

<分区>

我已经在我的系统上成功安装了 virtualenvvirtualenvwrapper。它工作得很好。为了将来的方便,我想创建一个脚本,将我最喜欢的所有模块安装到我命名为 pynumeric 的环境中,位于 ~/.virtualenvs 中。对于这个脚本,我需要在我的脚本中使用 virtualenvwrapper。不幸的是,这对我不起作用。我不断收到 workonmkvirtualenv 不存在的错误。

所以基本上我的问题归结为:为什么 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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com