[英]pip install error within Python 3 virtualenv
I created a Python 3 virtualenv, like this: 我创建了一个Python 3 virtualenv,如下所示:
mkproject -p python3 flowerid
But when I try to install anything with pip (inside this virtualenv) I get this error: 但是,当我尝试使用pip安装任何东西(在virtualenv内部)时,出现此错误:
cd flowerid
pip install ipython
Traceback (most recent call last):
File "/Users/nicolas/.virtualenvs/flowerid/bin/pip", line 11, in <module>
load_entry_point('pip==9.0.1', 'console_scripts', 'pip')()
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 560, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2648, in load_entry_point
return ep.load()
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2302, in load
return self.resolve()
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2308, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/__init__.py", line 28, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/vcs/subversion.py", line 9, in <module>
from pip.index import Link
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/index.py", line 31, in <module>
from pip.wheel import Wheel, wheel_ext
File "/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/pip/wheel.py", line 6, in <module>
import compileall
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/compileall.py", line 20, in <module>
from concurrent.futures import ProcessPoolExecutor
File "/Library/Python/2.7/site-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/Library/Python/2.7/site-packages/concurrent/futures/_base.py", line 357
raise type(self._exception), self._exception, self._traceback
^
SyntaxError: invalid syntax
Everything looks normal until the 'futures' import that goes to "/Library/Python/2.7". 在“ futures”导入到“ /Library/Python/2.7”之前,一切看起来都很正常。
I tried to set "--no-site-packages" when creating the virtualenv, but that doesn't change anything (and it shouldn't as it's the default). 我在创建virtualenv时尝试设置“ --no-site-packages”,但这并没有改变任何内容(默认情况下,它不应该如此)。
I tried to use pip3 instead, same thing. 我尝试使用pip3代替,同样的事情。
I tried to reinstall pip (in the virtualenv) with easy_install pip
, same thing... 我试图用
easy_install pip
重新安装pip(在virtualenv中),同样的事情...
Any other ideas? 还有其他想法吗? Thanks for your help.
谢谢你的帮助。
Note: I usually use Python 2.7 - I do have many Python 2.7 packages installed globally - perhaps that's what create the conflicts? 注意:我通常使用Python 2.7-我确实在全球安装了许多Python 2.7软件包-也许这就是造成冲突的原因?
I'm on OSX El Capitan. 我在OSX El Capitan上。
Update: My virtualenv seems activated - it starts off using the pip and python from my virtualenv. 更新:我的virtualenv似乎已激活-使用我的virtualenv中的pip和python开始。 And 'which python' uses python from the virtualenv.
并且“哪个python”使用virtualenv中的python。
(flowerid) nicolas@~/venv_projects/flowerid$ which python
/Users/nicolas/.virtualenvs/flowerid/bin/python
Ok, I figured it out. 好的,我知道了。 It was my environmental variable PYTHONPATH - that was messing things up - telling Python to look in the Python 2.7 libraries... I am setting up my PYTHONPATH in my .bashrc.
是我的环境变量PYTHONPATH-搞砸了-告诉Python在python 2.7库中查找...我正在.bashrc中设置我的PYTHONPATH。
So the solution is to change the PYTHONPATH on activation and setting back the previous setting on deactivation (it boggles my mind a bit that this is not default...) 因此,解决方案是在激活时更改PYTHONPATH并在停用时重新设置以前的设置(这让我有点困惑,这不是默认设置...)
So in /Users/nicolas/.virtualenvs/flowerid/bin/activate
add: 因此,在
/Users/nicolas/.virtualenvs/flowerid/bin/activate
添加:
# Fix PYTHONPATH imports
export OLD_PYTHONPATH="$PYTHONPATH"
export PYTHONPATH="/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/"
And in /Users/nicolas/.virtualenvs/flowerid/bin/postdeactivate
: 在
/Users/nicolas/.virtualenvs/flowerid/bin/postdeactivate
:
# Reset PYTHONPATH to previous state
export PYTHONPATH="$OLD_PYTHONPATH"
Here's where I found out what the problem was: virtualenv --no-site-packages and pip still finding global packages? 在这里,我发现了问题所在: virtualenv --no-site-packages和pip仍在查找全局软件包?
And the solution: How do you set your pythonpath in an already-created virtualenv? 解决方案: 如何在已经创建的virtualenv中设置pythonpath?
Try replacing the line in /Library/Python/2.7/site-packages/concurrent/futures/_base.py 尝试替换/Library/Python/2.7/site-packages/concurrent/futures/_base.py中的行
raise type(self._exception), self._exception, self._traceback
with this 有了这个
raise Exception(self._exception), self._exception, self._traceback
Try using pip3 instead of pip command. 尝试使用pip3代替pip命令。 Since you are using python 3.
由于您正在使用python 3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.