2016-02-05 66 views
3

我已經在python中使用:pip install eventlet安裝了eventlet庫。但是,當我試圖導入eventlet這個錯誤發生:ImportError:沒有名爲eventlet的模塊

$python 
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import eventlet 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named eventlet 

我試圖重新安裝,但我得到這個:

$pip install eventlet 
Requirement already satisfied (use --upgrade to upgrade): eventlet in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/eventlet-0.18.1-py3.5.egg 
Requirement already satisfied (use --upgrade to upgrade): greenlet>=0.3 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/greenlet-0.4.9-py3.5-macosx-10.6-intel.egg (from eventlet) 

如何糾正這個錯誤?

P.S:我使用Python 2.7

回答

5

這個問題是不特定於Eventlet,它只是對OSX管理的Python的多個版本。

您的pip命令安裝eventlet到/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5,見版本。

這意味着你實際上已經安裝了兩個Python版本:2.7和3.5和pip與3.5一起工作。

您的選擇:

  • (推薦)使用單獨的virtualenv [1]每一個項目,創建的virtualenv在使用virtualenv --python=python2.7 /path/to/new/venv
  • 運行python3和最新的Python
  • 運行使用eventlet明確指定Python版本pip2 install eventlet
  • 符號鏈接畫中畫PIP 2 ln -snf $(which pip2) $(which pip)

[1] http://docs.python-guide.org/en/latest/dev/virtualenvs/

+1

還建議,使用virtulenv包含Python解釋器和封裝http://docs.python-guide.org/en/latest/dev/virtualenvs/ –

+0

@therefromhere是的,謝謝,我在我的答案中插入了virtualenv選項,它確實是最好的選擇 – temoto

相關問題