gpt4 book ai didi

python - 为什么 pip 在 vi​​rtualenv 中写入/usr/lib?

转载 作者:太空狗 更新时间:2023-10-29 16:58:31 25 4
gpt4 key购买 nike

我在稍旧的操作系统上运行 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

关于python - 为什么 pip 在 vi​​rtualenv 中写入/usr/lib?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33130021/

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