Cannot import cv2 in python in OSX
Question:
I have installed OpenCV 3.1 in my Mac, cv2 is also installed through pip install cv2
.
vinllen@ $ pip install cv2
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already satisfied (use --upgrade to upgrade): cv2 in /usr/local/lib/python2.7/site-packages
But it looks like cv2
and cv
cannot be used:
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> import cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv
I have tried almost all the solutions list online, but cannot work.
Answers:
I do not know what pip install cv2
actually installs… but is surely not OpenCV. pip install cv2
actually installs this, which are some blog distribution utilities, not sure what it is, but it is not OpenCV.
To properly install OpenCV, check any of the links @udit043 added in the comment, or refer to any of the tutorials bellow:
Find here a tutorial on how to install OpenCV on OS X:
http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/
You need to actually compile OpenCV from source and activate python bindings, which takes a while.
Another option is to use brew
to get OpenCV, but doesn’t neccesarilly get you the last version nor a fully optimized one:
Make sure that numpy, other dependency is installed prior installing OpenCV
Also if you installed using PIP then check the installed packages using
pip freeze
I used
conda install opencv
and it installed fine for me.
You might want to try this if you are using Anaconda.
You can install by
conda install -c https://conda.binstar.org/menpo opencv
You can install by
pip install opencv-python
I had the same problem; here’s what worked for me: conda install -c conda-forge nb_conda
If you haven’t already, do the following to get conda up and running on OS X (taken from docs):
- Download Miniconda
- Download Anaconda
- Locate to the director that contains the Miniconda file and run
bash Miniconda3-latest-MacOSX-x86_64.sh
in Terminal
- Follow the prompts to install Anaconda
- Run
conda install -c conda-forge nb_conda
You could also try conda install -c conda-forge opencv
and conda install -c conda-forge/label/broken opencv
if step 5 doesn’t work, as someone recommended when I had the same problem. Hope this helps!
For me installation using conda didn’t worked.
While installing it using pip worked:
pip install opencv-python
os: macos Catalina
pip is renamed to pip3 so please use
pip3 install opencv-python
pip3 install opencv-python
Should do the job.
I have installed OpenCV 3.1 in my Mac, cv2 is also installed through pip install cv2
.
vinllen@ $ pip install cv2
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already satisfied (use --upgrade to upgrade): cv2 in /usr/local/lib/python2.7/site-packages
But it looks like cv2
and cv
cannot be used:
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> import cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv
I have tried almost all the solutions list online, but cannot work.
I do not know what pip install cv2
actually installs… but is surely not OpenCV. pip install cv2
actually installs this, which are some blog distribution utilities, not sure what it is, but it is not OpenCV.
To properly install OpenCV, check any of the links @udit043 added in the comment, or refer to any of the tutorials bellow:
Find here a tutorial on how to install OpenCV on OS X:
http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/
You need to actually compile OpenCV from source and activate python bindings, which takes a while.
Another option is to use brew
to get OpenCV, but doesn’t neccesarilly get you the last version nor a fully optimized one:
Make sure that numpy, other dependency is installed prior installing OpenCV
Also if you installed using PIP then check the installed packages using
pip freeze
I used
conda install opencv
and it installed fine for me.
You might want to try this if you are using Anaconda.
You can install by
conda install -c https://conda.binstar.org/menpo opencv
You can install by
pip install opencv-python
I had the same problem; here’s what worked for me: conda install -c conda-forge nb_conda
If you haven’t already, do the following to get conda up and running on OS X (taken from docs):
- Download Miniconda
- Download Anaconda
- Locate to the director that contains the Miniconda file and run
bash Miniconda3-latest-MacOSX-x86_64.sh
in Terminal - Follow the prompts to install Anaconda
- Run
conda install -c conda-forge nb_conda
You could also try conda install -c conda-forge opencv
and conda install -c conda-forge/label/broken opencv
if step 5 doesn’t work, as someone recommended when I had the same problem. Hope this helps!
For me installation using conda didn’t worked.
While installing it using pip worked:
pip install opencv-python
os: macos Catalina
pip is renamed to pip3 so please use
pip3 install opencv-python
pip3 install opencv-python
Should do the job.