在Linux的虚拟环境中使用python安装软件包(Bash to Python)

时间:2018-05-03 04:44:11

标签: python bash python-2.7 pip virtualenv

我正在创建一个虚拟环境并安装包。在shell脚本中,我可以安装所有的包。但在我的python代码中,在安装pytestpytest-cov等时收到权限被拒绝错误消息

外壳代码

VIRT_DIR=virt_folder
pip install --user virtualenv
virtualenv $VIRT_DIR
. $VIRT_DIR/bin/activate
pip install pylint
pip install coverage
pip install pytest
pip install pytest-cov
pip install virtualenvwrapper

Python代码(版本2.7)

VIRT_DIR = "virt_folder"
subprocess.call("pip install --user virtualenv", shell=True)
subprocess.call("virtualenv " + VIRT_DIR, shell=True)
subprocess.call(". " + VIRT_DIR + "/bin/activate", shell=True)
subprocess.call("pip install pylint", shell=True)
subprocess.call("pip install coverage", shell=True)
subprocess.call("pip install pytest", shell=True)
subprocess.call("pip install pytest-cov", shell=True)

错误讯息:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/site-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/usr/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib64/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/py'
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

0 个答案:

没有答案