为什么pip,在virtualenv中,写入/ usr/lib?

jal*_*anb 16 python pip virtualenv python-2.7

我在较旧的操作系统上运行Python,其系统Python版本为2.6.因此我在我的主目录中安装了2.7并使用该Python获取pip,并使用该pip来安装virtualenvwrapper.所以我有

$ which python pip virtualenv virtualenvwrapper.sh
/home/user/bin/python
/home/user/bin/pip
/home/user/.local/bin/virtualenv
/home/user/.local/bin/virtualenvwrapper.sh
Run Code Online (Sandbox Code Playgroud)

我使用这些工具创建virtualenv,并尝试安装模块

$ mkvirtualenv fred
New python executable in fred/bin/python2.7.10
Also creating executable in fred/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/preactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/postactivate
virtualenvwrapper.user_scripts creating /home/user/.virtualenvs/fred/bin/get_env_details

$ workon fred
$ export PYTHONPATH=/home/user/.virtualenvs/fred/lib/python2.7/site-packages
$ /home/user/.virtualenvs/fred/bin/easy_install --prefix=/home/user/.virtualenvs/fred pip
Creating /home/user/.virtualenvs/fred/lib/python2.7/site-packages/site.py
Searching for pip
Best match: pip 7.1.2
Adding pip 7.1.2 to easy-install.pth file
Installing pip script to /home/user/.virtualenvs/fred/bin
Installing pip3.4 script to /home/user/.virtualenvs/fred/bin
Installing pip3 script to /home/user/.virtualenvs/fred/bin

Using /home/user/.virtualenvs/fred/lib/python2.7/site-packages                                                                                                           
Processing dependencies for pip
Finished processing dependencies for pip

$ which python pip 
/home/user/.virtualenvs/fred/bin/python
/home/user/.virtualenvs/fred/bin/pip

$ pip install itsdangerous
Collecting itsdangerous
Installing collected packages: itsdangerous

Exception:
Traceback (most recent call last):
  File "/home/user/.local/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/home/user/.local/lib/python2.7/site-packages/pip/commands/install.py", line 311, in run
    root=options.root_path,
  File "/home/user/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 646, in install
    **kwargs
  File "/home/user/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 803, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/home/user/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 998, in move_wheel_files
    isolated=self.isolated,
  File "/home/user/.local/lib/python2.7/site-packages/pip/wheel.py", line 341, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/user/.local/lib/python2.7/site-packages/pip/wheel.py", line 319, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/usr/lib64/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/itsdangerous.py'
Run Code Online (Sandbox Code Playgroud)

为什么pip试图将模块安装到/ usr/lib中?不应该安装~/.virtualenvs/fred/lib,或~/lib

截至2018年7月4日的状态:不可复制,因为我无法访问该公司的服务器,因此我没有在其他系统上看到它.

Fab*_*amo 1

可能您正在调用系统级别pip而不是 virtualenv pip

您应该在以下操作之前激活您的 virtualenv

. bin/activate
Run Code Online (Sandbox Code Playgroud)