6

I am trying to install pyopencv with pip in OS X Mountain Lion and it fails by import setuptools. Following is my work. what is "Library" in setuptools? I have not seen that before. I already installed opencv via homebrew and other things. In doucmentation of pyopencv, it doesn't explain installation with 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 $

EDIT: I found setuptools source has Library and Extension (https://bitbucket.org/pypa/setuptools/src/27df3c725f9696ba730456f3f444cc2fb5271d4b/setuptools/extension.py?at=default) But I don't know why it doesn't recognize.

My setuptools' verison is 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 $
Jongsu Liam Kim
  • 662
  • 1
  • 5
  • 22

3 Answers3

3

In recent version of setuptools, Library is inside of extension.py. pyopencv should import Library as setuptools.extension.Library not setuptools.Library.

Jongsu Liam Kim
  • 662
  • 1
  • 5
  • 22
  • So… are you saying to `pip install extension` and that should fix it?  Or to change the source code of pyopencl before installing it?  And if the second… _seriously, what?_ – Slipp D. Thompson Nov 04 '14 at 23:25
  • It has been passed so long time from this question. I'm not using opencv now, however, pyopencv doesn't seems to be maintained and it seems opencv supports python binding itself. see this link http://www.jeffreythompson.org/blog/2013/08/22/update-installing-opencv-on-mac-mountain-lion/ (not sure for yosemite) and how about trying this method? – Jongsu Liam Kim Nov 17 '14 at 12:21
2

change

from setuptools import setup, find_packages, Extension, Library

to

from setuptools import *
from setuptools.extension import *
scum
  • 3,042
  • 1
  • 25
  • 27
Jan Cajthaml
  • 273
  • 1
  • 13
0

You can print python to run python interpreter and then print following inside python:

import sys
sys.path

Look for line similar to /Library/Python/2.7/site-packages in output. Print exit() to exit python interpreter.

In command line issue command: cd /Library/Python/2.7/site-packages and list files with ls command. Look for files 'cv.py' and 'cv2.so'. They should be there. Then refer to ~/.bash_profile file issuing command cat ~/.bash_profile to find your PYTHONPATH: there should be line similar to export PYTHONPATH=/usr/local/lib/python2.7/site-packages. Issue command cd /usr/local/lib/python2.7/site-packages to jump into that folder.

Now you could create symlinks for cv2.so and cv.py issuing commands: sudo ln -s /usr/local/lib/python2.7/site-packages/cv.py /Library/Python/2.7/site-packages/cv.py and sudo ln -s /usr/local/lib/python2.7/site-packages/cv2.so /Library/Python/2.7/site-packages/cv2.so.

Valeriy Van
  • 1,842
  • 16
  • 19
bluce
  • 1
  • 1
    Please consider proper formating of code or commands to make your answer more readable. Thanks and welcome at SA. Also, explain why you solution works. – Felix Aug 08 '15 at 08:30