Environment: Mac OS X Yosemite v10.10
Tools: MacPorts (download address), MacPorts is similar to the apt-get used in Ubuntu, it can easily install the application quickly, and can make the necessary compiling
Here are the steps:
1, download a macports according to the above download link, now is v2.3.3. and installation is completed;
2,command + space, find terminal and enter, the following instructions are entered in the terminal
3,> sudo port selfupdate
> sudo port install py27-numpy # Py27-numpy is a dependent library of OPENCV, mainly for its array
# When installing NumPy packages and other dependencies, the python2.7.9 will also be installed (if you have not previously installed)
# This process lasts about 30min, and our home is 100M fiber.
> sudo port install opencv +python27 # installs the OPENCV package and compiles it. After the installation is successful, you can use the import cv2 directly in Python
# There are a lot of dependencies to be installed, the brain is up and about to install 30~60min
The above installation smooth fortunately, if the network is very likely to cause some dependent package installation failed, encounter this situation do not fear, more than a few times, or a good environment for the network to continue to install
If a partial installation fails, you will see terminal prompts for errors characters
After installation, perform some necessary tests
1, test Python, enter terminal
> which Python
>/opt/local/bin/python # This result is correct, the wrong result please refer to the following considerations
> Python
>>> Import NumPy # If NumPy installation fails, there will be an error
>>> Import Cv2 # If OPENCV installation fails, there will be an error
>>> exit () # quit Python
Attention:
1, for the output of which Python, if the output is/library/frameworks/python.framework/versions/2.7/bin, it means that the Mac system comes with Python, And this python is not used in the OpenCV library,
Solution: Open terminal, enter > Export PATH = "/opt/local/bin:/opt/local/sbin: $PATH"
So, when we enter the Python directive, we prefer python under the two paths we added above, and this python is macports download and can refer to all MacPorts under the development package.
Welcome friends who have trouble to come to exchange