Python/OpenCV/numpy/scipy Installation for Mac OSX (using MacPorts)

Note Unfortunately, we weren’t able to figure out a way to install these tools on Mac systems without XCode, so you will need to download and run the XCode installer. This requires quite a large download (4GB), as well as giving your information to Apple to create a developer account. We are aware that this is very difficult for students with limited bandwidth and download caps, as well as generally inconvenient, but we were not able to work around it.

  • Make sure your system is up to date applications > preferences > updates.
  • Check if you already have XCode installed.
  • Open a terminal window (application > utilities > terminal) and type
 gcc -v
  • This should print a long string with information about the installed gcc version, if instead you see “command not found”. You have to install Xcode and the command line tools
  • Download and install XCode
  • For OSX 10.6.8 Snow Leopard, get XCode 3.2.6 (requires apple developer account).
  • For OSX 10.7+ (Lion and Mountain Lion), get the latest XCode 4 and command line tools. This can be done through the app store (requires that you enter credit card information), or through this link (requires only apple developer account). Command line tools can also be downloaded through
  • XCode once it is installed. XCode > Preferences > Downloads > Command Line Tools.
  • You can also install XCode via the App Store. The requirement for this is you need an AppleID for the App Store, which sometimes requires a Credit Card, even though the XCode download is free and you will not be charged.

Note For OSX 10.7+ (Lion and Mountain Lion), you need to allow third party applications to be installed. You can do this by going to application > system preferences > security and privacy. Click the lock in the bottom left corner and enter your password. Then, under ‘Allow applications downloaded from’, click ‘Anywhere’.

  • Download and install the macports package appropriate for your system. Follow the install instructions carefully and let the install finish before proceeding.
  • Open a new terminal window application > utilites > terminal and run
sudo port selfupdate
sudo port install python27 py27-numpy py27-scipy
sudo port install opencv +python27
sudo port select --set python python27
  • Verify your install by running these commands in a new terminal window:
python
  • This command will open the python shell, with the version of python and other statement, with a new line starting with >>>. In this shell type
import numpy
import scipy
import cv2
numpy.__version__
scipy.__version__
cv2.__version__

(Note the double underscores) If you see no errors, you are all set!

Advertisements

3 thoughts on “Python/OpenCV/numpy/scipy Installation for Mac OSX (using MacPorts)

  1. Hi, I tried doing everything you said, but I still get ImportError: No module named numpy when I try testing it in python. Is there another way to connect the modules together?

    Thanks

  2. Hey .. everything ran fine except the ‘import cv2’ .. I got this error
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv2.so, 2): Symbol not found: __XEatDataWords
    Referenced from: /opt/local/lib/libXrandr.2.dylib
    Expected in: /opt/local/lib/libX11.6.dylib
    in /opt/local/lib/libXrandr.2.dylib
    How do i resolve it ? thanks

  3. I was OK up to importing cv2:

    >>> import cv2
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cv2.so, 2): Symbol not found: __XEatDataWords
    Referenced from: /opt/local/lib/libXext.6.dylib
    Expected in: /opt/local/lib/libX11.6.dylib
    in /opt/local/lib/libXext.6.dylib

    Mountain Lion…and:

    dudes-macbook-pro:~ scharlesworth$ gcc -v
    Configured with: –prefix=/Applications/Xcode.app/Contents/Developer/usr –with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
    Target: x86_64-apple-darwin12.4.1
    Thread model: posix

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s