2013-09-24 83 views
6

我正嘗試在OS X Mountain Lion中使用pip安裝pyopencv,並且導入setuptools失敗。以下是我的工作。 setuptools中的「Library」是什麼?我以前沒有見過。我已經通過自制軟件和其他東西安裝了opencv。在pyopencv的doucmentation,它不能解釋與PIP只安裝源安裝,在Mac OS X上使用pip安裝pyopencv

(img2)[email protected] src $ brew install cmake 
Warning: cmake-2.8.11.2 already installed 
(img2)[email protected] src $ brew install cmake --upgrade 
Warning: cmake-2.8.11.2 already installed 
(img2)[email protected] src $ brew install opencv 
Warning: opencv-2.4.6.1 already installed 
(img2)[email protected] src $ brew install boost 
Warning: boost-1.54.0 already installed 
(img2)[email protected] src $ pip install pyopencv 
Downloading/unpacking pyopencv 
    Could not find a version that satisfies the requirement pyopencv (from versions: 2.0.wr1.0.1-demo, 2.0.wr1.0.1, 2.0.wr1.1.0, 2.1.0.wr1.0.0, 2.1.0.wr1.0.1, 2.1.0.wr1.0.2, 2.1.0.wr1.1.0, 2.1.0.wr1.2.0, 2.1.0.wr1.2.0-demo, 2.1.0.wr1.2.0) 
Cleaning up... 
No distributions matching the version for pyopencv 
Storing complete log in /Users/appleparan/.pip/pip.log 
(img2)[email protected] src $ pip install pyopencv==2.1.0.wr1.2.0 
Downloading/unpacking pyopencv==2.1.0.wr1.2.0 
    Downloading pyopencv-2.1.0.wr1.2.0.tar.gz (363kB): 363kB downloaded 
    Running setup.py egg_info for package pyopencv 
    Traceback (most recent call last): 
     File "<string>", line 16, in <module> 
     File "/Users/appleparan/.virtualenvs/img2/build/pyopencv/setup.py", line 92, in <module> 
     from setuptools import setup, find_packages, Extension, Library 
    ImportError: cannot import name Library 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 

    File "<string>", line 16, in <module> 

    File "/Users/appleparan/.virtualenvs/img2/build/pyopencv/setup.py", line 92, in <module> 

    from setuptools import setup, find_packages, Extension, Library 

ImportError: cannot import name Library 

---------------------------------------- 
Cleaning up... 
Command python setup.py egg_info failed with error code 1 in /Users/appleparan/.virtualenvs/img2/build/pyopencv 
Storing complete log in /Users/appleparan/.pip/pip.log 
(img2)[email protected] src $ python --version 
Python 2.7.5 
(img2)[email protected] src $ pip freeze 
Pillow==2.1.0 
distribute==0.7.3 
matplotlib==1.3.0 
nose==1.3.0 
numpy==1.7.1 
pyparsing==2.0.1 
python-dateutil==2.1 
scipy==0.12.0 
six==1.4.1 
stevedore==0.12 
tornado==3.1.1 
virtualenv==1.10.1 
virtualenv-clone==0.2.4 
virtualenvwrapper==4.1.1 
wsgiref==0.1.2 
(img2)[email protected] src $ 

編輯:我發現setuptools的來源有圖書館和擴展(https://bitbucket.org/pypa/setuptools/src/27df3c725f9696ba730456f3f444cc2fb5271d4b/setuptools/extension.py?at=default),但我不知道爲什麼它不承認。

我setuptools的verison是1.1.6

(img2)[email protected] src $ pip install setuptools --upgrade 
Requirement already up-to-date: setuptools in /Users/appleparan/.virtualenvs/img2/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg 
Cleaning up... 
(img2)[email protected] src $ 
+0

安裝最新版本的''setuptools'](https://pypi.python.org/pypi/setuptools)而不是'distribute'。 – falsetru

+0

我已經刪除了發佈,但它不能解決我的問題。 –

+0

在'distribute'移除後你安裝了'setuptools'嗎? – falsetru

回答

3

在最新版本的setuptools的,Libraryextension.py內。 pyopencv應該輸入Librarysetuptools.extension.Library而不是setuptools.Library

+0

所以......你是在說「pip install extension」,而且應該修復它?或者在安裝之前更改pyopencl的源代碼?如果第二個......很重要,什麼?_ –

+0

這個問題已經過了很長時間了。我現在沒有使用opencv,但是,pyopencv似乎沒有被維護,看來opencv支持python綁定本身。看到這個鏈接http://www.jeffreythompson.org/blog/2013/08/22/update-installing-opencv-on-mac-mountain-lion/(不知道優勝美地),以及如何嘗試這種方法? –

2

變化

from setuptools import setup, find_packages, Extension, Library 

from setuptools import * 
from setuptools.extension import * 
0

可以打印python運行Python解釋器,然後打印以下內部蟒蛇:

進口SYS
sys.path的

在輸出中尋找類似於/Library/Python/2.7/site-packages的行。 打印exit()退出python解釋器。

在命令行問題命令:cd /Library/Python/2.7/site-packages和列表文件與ls命令。尋找文件'cv.py'和'cv2.so'。他們應該在那裏。然後參考~/.bash_profile文件發佈命令cat ~/.bash_profile找到您的PYTHONPATH:應該有類似於export PYTHONPATH=/usr/local/lib/python2.7/site-packages的行。發出命令cd /usr/local/lib/python2.7/site-packages跳轉到該文件夾​​。現在

你可以爲cv2.so和cv.py發出命令創建符號鏈接: sudo ln -s /usr/local/lib/python2.7/site-packages/cv.py /Library/Python/2.7/site-packages/cv.pysudo ln -s /usr/local/lib/python2.7/site-packages/cv2.so /Library/Python/2.7/site-packages/cv2.so

+1

請考慮正確的格式化代碼或命令,以使您的答案更具可讀性。感謝並歡迎在SA。另外,解釋你的解決方案的工作原理 – Felix