A configuration problem of OpenCV4
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:
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
Where is code for
.format(fnames))
?I didn't change the ImportError message. The ".format(fnames))" is missing from the warning.
I have updated the progress. Please help.
Did you installed
anaconda3
?Can you show Cmake? You have both python 3.6 and 3.7 on it?
@supra56, I installed anaconda3 and its python 3.7 and uploaded my Cmake config's pic.
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
.OK! I found one solution. If this would help you.
Or Python 3:
In Cmake:
Btw. Change your path /home/user/anaconda3 instead of /home/test/SoftWare/anaconda3. And don't forget to clean your build folder.
According to your instruction, I have made the upgrade, then I corrected my Cmake config, and clean the build and rebuilt again. The same problem of missing configuration files appears again. It still generates a python 3.6 folder and config-3.6.py and some folders in /home/user/anaconda3/lib/python3.7/site-packages/cv2/ .
I noticed that you\re using opencv 4.0. I suggest you upgrading 4.1.2
Sorry, I was building and installing OpenCV 4.1. I think I have partially fixed my problem by upgrading my Ubuntu's Python to 3.7. But the Python 3 library used is not quite suitable. Please look into my second update.
I ensured that the Python3 library in Cmake is using '/home/user/anaconda3/lib/libpython3.7m.so' .