Python Pip默认行为与virtualenv冲突?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30604952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pip default behavior conflicts with virtualenv?
提问by Nils Guillermin
I was following this tutorial http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world/page/5
我正在关注本教程http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world/page/5
When I got to virtualenv flask
command, I received this error message:
当我得到virtualenv flask
命令时,我收到此错误消息:
Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
This makes sense as the point of virtualenv is to create a new environment which you can control, and the --user
command places everything in a specific location, defeating the objective of separation of dev environment.
这是有道理的,因为 virtualenv 的重点是创建一个您可以控制的新环境,并且该--user
命令将所有内容放在特定位置,从而破坏了分离开发环境的目标。
It seems like pip defaults to --user
installations though, can I change this default behavior? And, even better, can I get pip to play nice with virtualenv at all times?
--user
虽然pip 默认安装,但我可以更改此默认行为吗?而且,更好的是,我可以让 pip 始终与 virtualenv 一起玩吗?
To clarify, here is what my terminal looks like.
澄清一下,这是我的终端的样子。
MELCHIOR:miguelgrinberg-microblog megablanc$ virtualenv flask
New python executable in flask/bin/python
Installing setuptools, pip, wheel...
Complete output from command /Users/megablanc/Dev...log/flask/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/Users/megablanc/Library/Python/2.7/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 832, in main
symlink=options.symlink)
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 1004, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 969, in install_wheel
'PIP_NO_INDEX': '1'
File "/Users/megablanc/Library/Python/2.7/lib/python/site-packages/virtualenv.py", line 910, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/megablanc/Dev...log/flask/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 1
采纳答案by benlaird
You don't need to set the --user
flag. After you create your virtualenv (virtualenv flask
), activate it: source flask/bin/activate
. Your shell should look something like (flask) ~>
.
您不需要设置--user
标志。创建 virtualenv ( virtualenv flask
) 后,激活它:source flask/bin/activate
。你的外壳应该看起来像(flask) ~>
.
Once your virtualenv is activated, you should be able to pip install packages without issue. For example, pip install numpy
. They'll be installed in: lib/python2.6/site-packages/
(for whatever version of Python you are using)
一旦您的 virtualenv 被激活,您应该能够毫无问题地 pip 安装包。例如,pip install numpy
。它们将安装在:(lib/python2.6/site-packages/
对于您使用的任何版本的 Python)
回答by srikanth sridhar
There is a pip.conf file in ~/.pip. There I changed the flag user=true to user=false using the command gedit pip.conf
, after which I am able to create virtual environment successfully.
~/.pip 中有一个 pip.conf 文件。在那里我使用命令将标志 user=true 更改为 user=false gedit pip.conf
,之后我能够成功创建虚拟环境。
回答by jmunsch
In my case I was doing a make test
for the python disco
mapreduce library.
就我而言,我正在make test
为 python disco
mapreduce 库做一个。
So I modified the Makefile
test section and removed the --user
flag.
所以我修改了Makefile
测试部分并删除了--user
标志。
回答by Pratik Khadloya
In my case it was a custom python installation from anaconda was interfering with the system installation. Check which pip
... the solution is to either remove or move the custom installation of python.
在我的情况下,来自 anaconda 的自定义 python 安装干扰了系统安装。检查which pip
...解决方案是删除或移动python的自定义安装。
回答by MewX
In my case, there was a file in /etc/pip.conf
setting the user=true
secretly. So, every time I activated a virtualenv, that config still affected the virtualenv.
就我而言,有一个文件在秘密/etc/pip.conf
设置user=true
。因此,每次我激活 virtualenv 时,该配置仍然会影响 virtualenv。
Removing that line worked for me.
删除那条线对我有用。
回答by Erdin Eray
Some people suggest you to edit /etc/pip.conf
, which (i) requires superuser privileges and (ii) may break your whole system if done wrong. So, it is better to keep it to only your user.
有些人建议你编辑/etc/pip.conf
,这 (i) 需要超级用户权限,并且 (ii) 如果做错了可能会破坏你的整个系统。因此,最好仅将其保留给您的用户。
Open up$HOME/.pip/pip.conf
with a text editor. If it does not exist (which is the case in my Manjaro machine), create it. Then add the lines below, save and close.
$HOME/.pip/pip.conf
用文本编辑器打开。如果它不存在(在我的 Manjaro 机器中就是这种情况),请创建它。然后添加下面的行,保存并关闭。
[global]
user=false
When you change a setting for your programs, prefer under $HOME
for doing that if possible, which will (i) persist the setting among updates and reinstalling system (if you have separated your disk to /
and /home
, of course) and (ii) will not possibly break further upgrades of the program, in this case, pip
.
当您更改程序的设置时$HOME
,如果可能的话,更喜欢这样做,这将 (i) 在更新和重新安装系统之间保持设置(当然,如果您已将磁盘分离到/
和/home
)和 (ii) 不可能中断程序的进一步升级,在这种情况下,pip
.
回答by Fabian Bosler
what worked for me was to change the $VIRTUAL_ENV_DIRECTORY/pyvenv.cfg
to include-system-site-packages = true
seems hacky though.
对我有用的是将其更改$VIRTUAL_ENV_DIRECTORY/pyvenv.cfg
为include-system-site-packages = true
看起来很笨拙。