5

I've been trying to follow the opencv installation steps from pyimagesearch.com with virtualenv. Everything works fine except for the packages path: it should be /Users/JLee/Envs/cv/lib/python2.7/site-packages but it's configured as lib/python2.7/site-packages

In Python, import cv2 works well in the global setting but doesn't work in the 'cv' virtual environment.

While following the steps from the site, I first proceeded without installing virtualenv, then realized I haven't installed it so I installed it later and followed the steps again. Could this be a problem?

 Python 2:
--     Interpreter:                 /Users/JLee/Envs/cv/bin/python2.7 (ver 2.7.10)
--     Libraries:                   /usr/lib/libpython2.7.dylib (ver 2.7.10)
--     numpy:                       /Users/JLee/Envs/cv/lib/python2.7/site-packages/numpy/core/include (ver 1.11.1)
--     packages path:               lib/python2.7/site-packages

This is the code for cmake to configure the build:

cmake -D CMAKE_BUILD_TYPE=RELEASE 
-D CMAKE_INSTALL_PREFIX=/usr/local \ 
-D PYTHON2_PACKAGES_PATH=/Users/JLee/Envs/cv/lib/python2.7/site-packages \ 
-D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin \ 
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers \ 
-D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON \ -D BUILD_EXAMPLES=ON \ 
-D OPENCV_EXTRA_MODULES_PATH=/Users/JLee/Developer/opencv_project/opencv_contrib/modules ..

Thanks for the help in advance!

1 Answer 1

5

For some reason it looks like CMake didn't automatically determine your site-packages directory for your virtual environment. That's not an issue though, because all you need to do is sym-link in the cv2.so file.

Find your cv2.so file on disk (based on your output, it seems to be in lib/python2.7/site-packages) and then sym-link into your Python virtual environment site-packages directory. From there, everything will work as expected.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks this helped me as well. I had exactly the same problem as Jooyeon and couldn't import many of the modules, especially the ones in opencv_contrib, but this solved the problem.
This is more of a treatment for the symptoms than a cure. I'd prefer to know why CMake is having problems with my Conda install, but I'll settle for a working install from source. Thank you for getting me this far.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.