A configuration problem of OpenCV4

asked 2019-11-18 07:43:58 -0600

cv_new gravatar image

updated 2019-11-22 02:28:11 -0600

I built the OpenCV4 by Cmake and installed the opecv4.0 using anaconda3 with its python 3.7 verison. My platform is Ubuntu 18.04 LTS. However, when testing the installation, I encounter the following problem:

ype "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/anaconda3/lib/python3.7/site-packages/cv2/__init__.py", line 89, in <module>
    bootstrap()
  File "/home/user/anaconda3/lib/python3.7/site-packages/cv2/__init__.py", line 62, in bootstrap
    ], True)
  File "/home/user/anaconda3/lib/python3.7/site-packages/cv2/__init__.py", line 56, in load_first_config
    raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config-3.7.py', 'config-3.py']. Check OpenCV installation.
>>>

I typed the command:

echo $PYTHONPATH

I get:

/home/user/anaconda3/lib/python3.7/site-packages

Updated:

I found that the /home/user/anaconda3/lib/python3.7/site-packages/cv2/ does not contain the config-3.7.py, but it contains config-3.6.py. At the beginning, I ensured that all python3 are correlated to the anaconda's python 3.7 library. I don't know why the cv2 folder still uses the Ubuntu's default python.

I have tried deleting the cv2 folder and rebuild it again, but it still generates the config-3.6.py file. I don't know why it will like this.

By the way, I didn't turn on the opencv python3 verison in Cmake config of building OpenCV, will it be affected?

Please help. Thanks

A part of Cmake is here: Cmake

After modifying the Cmake config following the instruction from and removing python2 related setting , I clear the build folder and rebuilt again. I did pip3 install --upgrade, but the cv2 folder still contain the config-3.6.py.

Second update:

I have upgraded the Ubuntu's Python from 3.6 to 3.7 according to this tutorial ((http://ubuntuhandbook.org/index.php/2019/02/install-python-3-7-ubuntu-18-04/)) and run this command "sudo apt-get install python3.7-dev" . The above errors disappear and the command "import cv2" can run now. But I find some special pointing locations when installing OpenCV4.1. The python3 library used is User's library instead of Anaconda's.

--   Python 2:
--     Interpreter:                 (ver 2.7.15)
--     Libraries:                   NO
--     numpy:                       NO (Python wrappers can not be generated)
--     install path:                -
-- 
--   Python 3:
--     Interpreter:                 /home/user/anaconda3/bin/python3.7m (ver 3.7.5)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.7m.so (ver 3.7.5)
--     numpy:                       /home/user/anaconda3/lib/python3.7/site-packages/numpy/core/include (ver )
--     install path:                /home/user/anaconda3/lib/python3.7/site-packages/cv2/python-3.7
-- 
--   Python (for build):            /home/user/anaconda3/bin/python3.7m
edit retag flag offensive close merge delete

Comments

Where is code for .format(fnames))?

supra56 gravatar imagesupra56 ( 2019-11-18 11:36:43 -0600 )edit
1

I didn't change the ImportError message. The ".format(fnames))" is missing from the warning.

cv_new gravatar imagecv_new ( 2019-11-18 18:57:54 -0600 )edit
1

I have updated the progress. Please help.

cv_new gravatar imagecv_new ( 2019-11-19 08:18:27 -0600 )edit

Did you installed anaconda3?

supra56 gravatar imagesupra56 ( 2019-11-19 09:08:41 -0600 )edit

Can you show Cmake? You have both python 3.6 and 3.7 on it?

supra56 gravatar imagesupra56 ( 2019-11-19 09:10:29 -0600 )edit
1

@supra56, I installed anaconda3 and its python 3.7 and uploaded my Cmake config's pic.

cv_new gravatar imagecv_new ( 2019-11-20 03:25:50 -0600 )edit

I was looking at screenshot that you adding both python 2 and python 3. I suggest you remove python2 only from Cmake. Your python looked okay to me. Here is link: anaconda3 and its python 3.7 . There is something missing config-3.py.

supra56 gravatar imagesupra56 ( 2019-11-20 06:03:40 -0600 )edit

OK! I found one solution. If this would help you.

pip install --upgrade opencv-python
pip install --upgrade pyinstaller

Or Python 3:

pip3 install --upgrade opencv-python
pip3 install --upgrade pyinstaller
supra56 gravatar imagesupra56 ( 2019-11-20 06:11:53 -0600 )edit

In Cmake:

cmake -D CMAKE_BUILD_TYPE=Release \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.7/modules \
      -D PYTHON3_EXECUTABLE='/home/test/SoftWare/anaconda3/bin/python3.7m' \
      -D PYTHON_INCLUDE_DIR='/home/test/SoftWare/anaconda3/include/python3.7m' \
      -D PYTHON3_LIBRARY='/home/test/SoftWare/anaconda3/lib/libpython3.7m.so' \
      -D PYTHON3_NUMPY_INCLUDE_DIRS='/home/test/SoftWare/anaconda3/lib/python3.7/site-packages/numpy/core/include' \
      -D PYTHON3_PACKAGES_PATH='/home/test/SoftWare/anaconda3/lib/python3.7/site-packages' ..
supra56 gravatar imagesupra56 ( 2019-11-20 06:20:18 -0600 )edit

Btw. Change your path /home/user/anaconda3 instead of /home/test/SoftWare/anaconda3. And don't forget to clean your build folder.

supra56 gravatar imagesupra56 ( 2019-11-20 06:23:03 -0600 )edit