6

我正在尝试在 OS X Mountain Lion 中使用 pip 安装 pyopencv,但导入 setuptools 失败。以下是我的作品。setuptools 中的“库”是什么?我以前没见过。我已经通过自制软件和其他东西安装了 opencv。在 pyopencv 的文档中,它没有解释使用 pip only source install 安装,

(img2)appleparan@LiamMac src $ brew install cmake
Warning: cmake-2.8.11.2 already installed
(img2)appleparan@LiamMac src $ brew install cmake --upgrade
Warning: cmake-2.8.11.2 already installed
(img2)appleparan@LiamMac src $ brew install opencv
Warning: opencv-2.4.6.1 already installed
(img2)appleparan@LiamMac src $ brew install boost
Warning: boost-1.54.0 already installed
(img2)appleparan@LiamMac 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)appleparan@LiamMac 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)appleparan@LiamMac src $ python --version
Python 2.7.5
(img2)appleparan@LiamMac 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)appleparan@LiamMac src $

编辑:我发现 setuptools 源有库和扩展(https://bitbucket.org/pypa/setuptools/src/27df3c725f9696ba730456f3f444cc2fb5271d4b/setuptools/extension.py?at=default)但我不知道为什么它不能识别。

我的 setuptools 版本是 1.1.6

(img2)appleparan@LiamMac 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)appleparan@LiamMac src $
4

3 回答 3

3

在最新版本的 setuptools 中,Library位于extension.py. pyopencv 应该导入Librarysetuptools.extension.Librarynot setuptools.Library

于 2013-09-24T22:48:03.480 回答
2

改变

from setuptools import setup, find_packages, Extension, Library

from setuptools import *
from setuptools.extension import *
于 2013-12-03T09:08:52.690 回答
0

您可以打印python以运行 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.

于 2015-08-08T08:25:51.087 回答