I have installed OpenCV on the Occidentalis operating system (a variant of Raspbian) on a Raspberry Pi, using jayrambhia’s script found here: https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/opencv_latest.sh. It installed version 2.4.5.
When I try to import the module cv2 in a python program, I get the following message:
[email protected]~$ python cam.py Traceback (most recent call last) File "cam.py", line 1, in <module> import cv2 ImportError: No module named cv2
cv2.so is stored in
There are also folders in /usr/local/lib called python3.2 and python2.6, which could be a problem but I’m not sure.
Is this a path error perhaps? Any help appreciated (new to Linux).
This happens when python cannot refer to your default site-packages folder where you have kept the required python files or libraries
Add these lines in the code:
import sys sys.path.append('/usr/local/lib/python2.7/site-packages')
or before running the python command in bash move to /usr/local/lib/python2.7/site-packages directory. This is a work around if you don’t want to add any thing to the code.
for windows if you have anaconda installed, you can simply do
pip install opencv-python
conda install -c https://conda.binstar.org/menpo opencv
if you are on linux you can do :
pip install python-opencv
conda install opencv
Try to add the following line in
I solved my issue using the following command :
conda install opencv
I have come accross same as this problem i installed cv2 by
pip install cv2
However when i import cv2 module it displayed no module named cv2 error.
Then i searched and find
cv2.pyd files in my computer and i copy and paste to site-packages directory
then i closed and reopened existing application, it worked.
I will tell how to install
1. Firstly install numpy on your computer by
pip install numpy
2. Download opencv from internet (almost 266 mb).
opencv-2.4.12.exe for python 2.7. Then install this opencv-2.4.12.exe file.
I extracted to
C:\Users\harun\Downloads to this folder.
After installation go look for
cv2.py into the folders.
in this folder take the
cv2.pyd and copy it in to the
now you can able to use
cv2 in you python scripts.
Try this out:
sudo ldconfig sudo nano /etc/ld.so.conf.d/opencv.conf
and add this following line in the
opencv.conf not in the command window
sudo ldconfig sudo nano /etc/bash.bashrc
and add this two lines in the
bash.bashrc not in the command window
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
at last reboot your Pi
sudo reboot now
I had the same problem, just couldn’t figure it out with opencv2 and opencv3 installed into /opt/opencv and opencv3 respectively. Turned out that bloody anaconda install of opencv in my home directory was first on path and mangled opencv. Removed it and started using /opt/opencv3/lib as defined in /etc/ld.so.conf.d/opencv.conf. Worked perfectly first go. Do you have anaconda installed? Could be the issue.