简体   繁体   中英

OpenCV install with MacPorts, already have python2.7 installed but cannot 'import cv'

Just get started with my opencv project and trying to install opencv on my mac. What i have right now is my macport will show:

 opencv @3.0.0_1+python27 (active)

but i couldn't do import cv when i run python in the terminal. Currently i have also installed pycharm, which seems like it comes with python2.6 , will this be a problem?

Any help will be much appreciate, thanks in advance!

With macports, you need to set the default system python. The issue may be that you are still using the Apple default python. To check, first run

$ which python
/opt/local/bin/python

That should inform you about which python. If your python is in /usr/bin, then it could be invalid.

Next, configure the default python to the 2.7 version where you installed OpenCV for.

$ sudo port select --summary
Password:
Name        Selected       Options
====        ========       =======
python      python27       python26-apple python27 python27-apple        
python2     python27       python27 none
python3     none           python34 none

To set the python version

sudo port select --set python python27

Just because Apple gives you python2.7, does not mean that the MacPorts libraries are going to link to it. The nice part with the MacPort version is that they have all of that worked out.

As far as pycharm is concerned, you may not need to set the default python in the console. Pycharm can link directly to it. Just go to the project settings, and configure the interpreter to /opt/local/bin/python2.7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM