top of page

Install OpenCV in Anaconda to use Spyder

I use Python(x,y) (https://python-xy.github.io/) to program python 2.7, the most important reason is that it has the Spyder built inside. Spyder has a very similar interface to MATLAB, in which I have access to variables through the "variable explorer". It's super useful to me who don't have the magic feeling what dimension one array or matrix is.

For the "Self-Driving Car" program, we use python 3. The reason is explained as follows:

"Python versions at Udacity

Most Nanodegree programs at Udacity will be (or are already) using Python 3 almost exclusively.

Why we're switching to Python 3

  • Jupyter is switching to Python 3 only

  • Python 2.7 is being retired

  • Python 3.6 has great features such as formatted strings

At this point, there are enough new features in Python 3 that it doesn't make much sense to stick with Python 2 unless you're working with old code. All new Python code should be written for version 3."

(https://classroom.udacity.com/courses/ud1111/lessons/c6a12f2e-63f2-4007-a2c3-dd3e5f06f3cb/concepts/5e87a70d-c147-422b-b120-f89a392ba154)

My installed Anaconda3 has spyder3. In order to install OpenCV, I followed the OpenCV3 Tutorials 1: Installing OpenCV 3 on Anaconda (https://www.youtube.com/watch?v=9hb0gYCv3YI&t=6s) and it didn't work. When "import cv2" in spyder3, it gave error "ImportError: DLL load failed: The specified module could not be found". In fact, I started to doubt the instruction when I saw python 2.7 (1:40 in the video), and it's real the problem. I googled and found some useful information here: DLL load failed error when importing cv2 (https://stackoverflow.com/questions/43184887/dll-load-failed-error-when-importing-cv2). In fact, there are developed unofficial OpenCV package based on python 3.x : https://pypi.python.org/pypi/opencv-python. The steps I followed can be summarized as:

  • In Anaconda3 cmd, type "python --version" to find whether your python version

  • Download the latest OpenCV 3.x.0 for Python 3.6 for Windows (http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv). I downloaded "opencv_python‑3.3.0‑cp36‑cp36m‑win_amd64.whl", in which cp36 stands for python 3.6 version.

  • Put "opencv_python‑3.3.0‑cp36‑cp36m‑win_amd64.whl" into python3 folder inside Anaconda3: Anaconda3\pkgs\python-3.6.2-h6679aeb_11.

  • In Anaconda3 cmd, activate the the environment you would like to work in first, then change directory: "cd Anaconda3\pkgs\python-3.6.2-h6679aeb_11", then type command toinstall it: "pip install opencv_python-3.3.0-cp36-cp36m-win_amd64.whl"

  • Check in Spyder3, "import cv2".

It should works fine now. If not, do the following two steps before conducting above steps:

  • Download python 3.x.x embeddable zip file (https://www.python.org/downloads/windows/)

  • Extract the zip file and copy "python3.dll" file to Anaconda3 folder

Software is tricky!!!


Recent Posts
Archive
bottom of page