2017-05-29 109 views
0

我創建了一個Python 3 virtualenv中,像這樣:PIP內的Python 3安裝錯誤的virtualenv

mkproject -p python3 flowerid 

但是,當我嘗試安裝與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 

在「期貨」導入到「/Library/Python/2.7」之前,一切看起來都很正常。

我在創建virtualenv時試圖設置「--no-site-packages」,但這並沒有改變任何東西(它不應該是默認設置)。

我試着用pip3代替,同樣的事情。

我試圖與easy_install pip,同樣的事情重新安裝PIP(在virtualenv中)...

任何其他的想法?謝謝你的幫助。

注意:我通常使用Python 2.7 - 我在全局安裝了很多Python 2.7包 - 也許這就是創建衝突的原因?

我在OSX El Capitan。

更新: 我的virtualenv似乎被激活 - 它開始使用我的virtualenv中的pip和python。而'哪個python'使用virtualenv的python。

(flowerid) [email protected]~/venv_projects/flowerid$ which python 
/Users/nicolas/.virtualenvs/flowerid/bin/python 
+1

你有沒有任何機會忘了激活的virtualenv? –

+0

'File「/Library/Python/2.7/site-packages ....'注意__2.7__ _Python_版本。 – CristiFati

+0

您是否在運行pip時激活了virtualenv?什麼'哪個python'顯示(或者你使用的任何類似的命令)? – Nurjan

回答

0

好吧,我明白了。這是我的環境變量PYTHONPATH - 這搞砸了 - 告訴Python在Python 2.7庫中查找......我在我的.bashrc中設置我的PYTHONPATH。

因此,解決辦法是改變在激活時該PYTHONPATH和設置回停用原來的設置(它博格爾斯我的腦子有點,這是不是默認?)

所以在/Users/nicolas/.virtualenvs/flowerid/bin/activate加:

# Fix PYTHONPATH imports 
export OLD_PYTHONPATH="$PYTHONPATH" 
export PYTHONPATH="/Users/nicolas/.virtualenvs/flowerid/lib/python3.6/site-packages/" 

而且在/Users/nicolas/.virtualenvs/flowerid/bin/postdeactivate

# Reset PYTHONPATH to previous state 
export PYTHONPATH="$OLD_PYTHONPATH" 

此處,我發現了問題所在:virtualenv --no-site-packages and pip still finding global packages?

而且該解決方案: How do you set your pythonpath in an already-created virtualenv?

-1

嘗試與此

raise Exception(self._exception), self._exception, self._traceback 
0

更換線/Library/Python/2.7/site-packages/concurrent/futures/_base.py

raise type(self._exception), self._exception, self._traceback 

嘗試使用PIP3代替的點子命令。因爲你使用的是python 3.

+0

我嘗試過,同樣的事情。它啓動使用Python3,然後由於某種原因導入期貨時切換到Python 2.7。 – Tickon

+0

你有沒有嘗試過運行這個,python文檔中的例子: 'python3 -m pip install SomePackage' – MDK