问题描述
我有一个用于 django 应用程序的 python 虚拟环境.我用...激活它
I have a python virtual env that I am using for a django application. I activate it with...
source venv/bin/activate
那行得通,但是我在尝试运行 pip install 时得到了这个回溯...
that works, but then I get this traceback when trying to run a 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 中安装某些东西?
So why would it be trying to install something in /usr when I am supposed to be running in the venv?
添加了输出virtualenv venv
added the output of virtualenv venv
New python executable in venv/bin/python
Installing setuptools, pip...done.
当我使用 source 启动那个 venv 并运行哪个 python 我得到这个...
and when I use source to start that venv and run which python I get this...
/home/user/Desktop/test/venv/bin/python
推荐答案
检查which pip
的输出,最有可能的 pip 没有安装.如果它不是来自 venv 的 pip 还要检查 which python
.如果不是 venv 的 python,则说明您不在新环境中 - 应该有一些错误.
Check the output of which pip
, most likly pip is not installed. If it is not pip from venv also check which python
. If it is not venv's python, your are not in the new env - there should be some errors.
如果只缺少 pip 尝试安装:
If only pip is missing try to install with:
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python
编辑
Virualenv 仅适用于当前的 shell 会话.要在另一个会话/终端/窗口中使用,您必须再次激活它.它会一直存在,直到您停用
它.
Virualenv is only for current shell session. To use in another session/terminal/window you must activate it again. It persists until you deactivate
it.
这篇关于python虚拟环境正在安装到/usr/...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!