[Solved] Pyinstaller package opencv error: ImportError: OpenCV loader: missing configuration file: [‘config.py’]. Check OpenCV installation.

Before packaging, it was OK. After upgrading pyinstaller and opencv, an error will be reported. I looked up a circle of information and found the answer on GitHub.

ImportError: OpenCV loader: missing configuration file: [‘config.py’]. Check OpenCV installation.

In

Pyinstaller 4.6
opencv Python 4.5.3.58
encountered a problem

 

Solution:

Solution 1

Reduce the opencv Python version to 4.5.3.56. This small version iteration actually changed something, resulting in packaging failure.

Solution 2

PS: I tried this method several times and failed

import cv2
print(cv2.__file__)

Execute these two sentences to find the path where CV2 is located:

D:\anaconda\64\lib\site-packages\cv2\cv2.cp38-win_ AMD64. PYD
this is my path
when packaging:

pyinstaller -F -w --key '12345678' --clean main.py --paths="D:\anaconda\64\lib\site-packages\cv2"

Remove the last file name from the path and keep the whole folder.

I suggest using the second scheme, because it is not constrained by the version, and this problem can be solved in a similar way in other packages in the future.

Read More: