0
votes

I'm trying to install a complete OpenCV 3.4.2 on ubuntu 18.04, within a conda environment named "tf". This is my cmake command :

$ source activate tf

$ cd ~/Downloads/opencv-3.4.2/build/

$ cmake -D CMAKE_BUILD_TYPE = RELEASE \

 -D CMAKE_INSTALL_PREFIX = /usr/local \

 -D INSTALL_PYTHON_EXAMPLES = ON \

 -D INSTALL_C_EXAMPLES = OFF \

 -D OPENCV_EXTRA_MODULES_PATH = ~\Downloads\opencv_contrib-3.4.2\modules \

 -D PYTHON_EXECUTABLE = ~/anaconda3/envs/tf/bin/python \

 -D BUILD_EXAMPLES = ON ..

$ make

$ sudo make install

$ sudo ldconfig

I didn't see anything wrong during the install. The command :

$ pkg-config --modversion opencv

returns '3.4.2', which is expected.

But the problem is that I can'f find anywhere the file "cv2.cpython-36m-x86_64-linux-gnu.so". It should be within "/usr/local/lib/python3.6/site-packages/", but it's not. I look everywhere (even within the directories of my environment 'tf' : '~/anaconda3/envs/tf').

What went wrong ? How can I fix it ?

Thanks

2

2 Answers

0
votes

I've found my answer.

If you use conda environments, you must use this cmake configuration :

cmake -D CMAKE_BUILD_TYPE=RELEASE \

-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-3.4.2/modules \
-D PYTHON_EXECUTABLE=~/anaconda3/envs/tf/bin/python \
-D BUILD_opencv_python2=OFF \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D BUILD_EXAMPLES=ON ..

After you install openCV with this configuration, you can directly import it into python with 'import cv2'

0
votes

I have successfully installed opencv in my ubuntu 18.04 LTS using below command.

`pip install opencv-python`