![](/img/trans.png)
[英]pip installing in usr/lib/python3.6/site-packages instead of virtualenv on ubuntu server
[英]Why is pip, inside a virtualenv, writing to /usr/lib?
我在较旧的操作系统上运行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
我使用这些工具创建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'
为什么pip试图将模块安装到/ usr / lib中? 不应该安装到~/.virtualenvs/fred/lib
或~/lib
?
截至2018年7月4日的状态:不可复制,因为我无法访问该公司的服务器,因此我没有在其他系统上看到它。
可能你正在调用系统级别的pip
而不是virtualenv pip
。
你应该在之前激活你的virtualenv :
. bin/activate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.