python虚拟环境正在安装到/ usr / ...?

时间:2015-12-11 01:05:27

标签: python virtualenv

我有一个用于django应用程序的python虚拟环境。我用......激活它。

source venv/bin/activate

有效,但是当我尝试运行pip install时,我得到了这个回溯......

Installing collected packages: django-blog-zinnia
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
    pycompile=self.pycompile,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
    os.makedirs(destsubdir)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/zinnia'

Storing debug log for failure in /home/jeff/.pip/pip.log

那么为什么当我应该在venv中运行时,它会尝试在/ usr中安装一些东西?

添加了输出     virtualenv venv

New python executable in venv/bin/python
Installing setuptools, pip...done.

当我使用source启动那个venv并运行哪个python时我得到了这个......

/home/user/Desktop/test/venv/bin/python

1 个答案:

答案 0 :(得分:0)

检查which pip的输出,大多数人都没有安装pip。如果不是来自venv,请检查which python。如果它不是venv的python,你不在新的环境中 - 应该有一些错误。

如果只缺少pip,请尝试安装:

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python

修改

Virualenv仅适用于当前的shell会话。要在另一个会话/终端/窗口中使用,您必须再次激活它。它会持续到你deactivate为止。