2013-08-28 105 views
2

在獲得O'Reilly書之前,我正在玩Python的熊貓包。當我在成功安裝xcode和EPDFree後嘗試安裝熊貓時,使用easy_install的熊貓安裝提出了很多警告,並且當我測試瞭解熊貓是否工作時,它顯然不是。我試圖刪除並重新安裝熊貓和Numpy幾次,但沒有成功。我對此很陌生,所以我一定做錯了什麼。在Mac OSX上安裝熊貓和numpy的問題

這是我所得到的,當我運行Python和嘗試導入熊貓和numpy的:

$ python 
Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import numpy 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named numpy 
>>> import pandas 
No module named numpy 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Library/Python/2.7/site-packages/pandas-0.12.0-py2.7-macosx-10.8-intel.egg/pandas/__init__.py", line 6, in <module> 
    from . import hashtable, tslib, lib 
    File "numpy.pxd", line 157, in init pandas.hashtable (pandas/hashtable.c:19547) 
ImportError: No module named numpy 

有沒有一種方法,我可以解決這個問題或者與整個安裝重新開始嗎?

下面是一些更多的信息,當我嘗試安裝熊貓和numpy的:

$ sudo easy_install pandas 
Password: 
Searching for pandas 
Best match: pandas 0.12.0 
Processing pandas-0.12.0-py2.7-macosx-10.8-intel.egg 
pandas 0.12.0 is already the active version in easy-install.pth 

Using /Library/Python/2.7/site-packages/pandas-0.12.0-py2.7-macosx-10.8-intel.egg 
Processing dependencies for pandas 
Finished processing dependencies for pandas 

$ sudo easy_install numpy 
Searching for numpy 
Best match: numpy 1.6.1 
numpy 1.6.1 is already the active version in easy-install.pth 

Using /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python 
Processing dependencies for numpy 
Finished processing dependencies for numpy 

回答

2

開始在更清潔的方式。如果你打算用Python做任何工作,特別是在安裝額外的軟件包方面,我建議你尋找pyenvvirtualenv之類的工具。 Pyenv讓你輕鬆管理和切換多個版本(包括微版本x.x.3,x.x.5等)。 Virtualenv允許您創建獨立的Python環境,您可以在其中定製針對特定項目的站點包的版本。

剛開始使用的virtualenv:

它會像

$ pip install virtualenv 
$ virtualenv foo 
$ source foo/bin/activate 
$ pip install pandas 
$ pip install numpy 

或者,使用pyenv +的virtualenv(超過Python版本額外的控制,如指定2.7.2),第一install pyenv,則:

$ pip install virtualenv 
$ pyenv install 2.7.2 
$ pyenv shell 2.7.2 
$ virtualenv `which python` foo 
$ source foo/bin/activate  
$ pip install pandas 
$ pip install numpy 
0

小心右側的python版本啓動。如果您使用brew版本:which python應返回/usr/local/bin

如果不是這種情況,請檢查.bash_profile中的$ PATH環境變量。

這對我有用。我想這與使用easy_install比brew和pip類似。