# error in running exe file after changing .py to .exe

I have changed my python code to an .exe file using pyinstaller and anaconda. In my python script ("untitled.py") I import opencv which I have already installed from source using cmake. After creating exe file I run untitled.exe in cmd windows. However, I get the following error:

File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module File "cv2_init_.py", line 96, in File "cv2_init_.py", line 58, in bootstrap File "cv2_init_.py", line 56, in load_first_config ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.

There is config.py in OpenCV folder, but it cannot be found. I tried this:

pyinstaller -F  --hidden-import ‘OpenCV’ untitled.py


But still does not work. I wanted to ask how I can solve this issue?

## 1 Answer

A quick google search of the error message reveals two issues describing the issue and potential solutions.

One of the issues is in the pyinstaller repo, and suggests adding the cv2 path to the pyinstaller invocation:

pyinstaller --onefile sample.py --paths "/root/opencv-4.3.0/release/lib/python3/cv2"


You can get the actual path by running a simple python program:

import cv2
print(cv2.__file__)


The other issue is in the opencv repo and may apply especially if you compiled opencv yourself.

UPDATE: with respect to the error ImportError: DLL load failed while importing cv2, according to the FAQ, you should install the Visual Studio C++ redistributable

• Thank you for your reply. I got the actual path, which is "C:/Users/simin/anaconda3/Lib/site-packages/cv2\python-3.8\cv2.cp38-win_amd64.pyd", then I used the following command: pyinstaller --onefile untitled3.py --paths "C:/Users/simin/anaconda3/Lib/site-packages/cv2" . However, I still get the same error Feb 4 at 9:05
• Another option is the upgrade suggested in this stackoverflow answer.
– noe
Feb 4 at 9:34
• Thank you. I could solve the issue by using  pyinstaller --onefile untitled3.py --paths "C:\Users\simin\anaconda3\Lib\site-packages\cv2\python-3.8" . However, I get another error: ImportError: DLL load failed while importing cv2: The specified module could not be found. Feb 4 at 19:10
• I updated the answer with the information regarding this new problem.
– noe
Feb 4 at 20:57
• Thanks. everything is fine when I use opendcv in python editors or for running yolov3 from darknet repository. However, this error appears when trying to change .py to .exe. By the way I have installed opencv from source not using pip, and have visual studio c++ redistributable Feb 4 at 22:17