Wrong python packages path for opencv cmake installation

99封情书 提交于 2019-12-06 03:59:48

问题


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:


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.



来源:https://stackoverflow.com/questions/38500617/wrong-python-packages-path-for-opencv-cmake-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!