程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The program packaged by python nuitka prompts ImportError: DLL load failed while importing cv2: The specified module cannot be found.

編輯:Python

Use scenario:

After python nuitka has packaged the program and moved the cv2 library file to the program directory, it can be run in the python environment. After leaving the python environment, it will prompt: ImportError: DLL load failed while importing cv2: cannot find the specifiedmodule.

Treatment ideas:

1 . Because my program can run in the python environment, it means that the cv2 in my environment can be used normally.
2. The packaged program can be run in the python virtual environment, indicating that the packaged program has no problem.
3. After the packaged program leaves the python virtual environment, it prompts that the cv2 module cannot be found, indicating that it is caused by the cv2 import package.

Therefore, I just need to solve the exception problem after cv2 introduces the package.

Refer to the solutions provided by many netizens:

  1. Reinstall the cv2 library
pip uninstall opencv-pythonpip uninstall opencv-contrib-pythonpip install opencv-pythonpip install opencv-contrib-python
  1. Configure in IDEA Add the directory where cv2 is located to the environment variable

  2. Use Dependency Walker to check for missing dll dependencies in file cv2.pyd in cv2, to reimport.

  3. Modify the pyd file name in the cv2 folder to cv2.pyd

Because I need to package it and provide it to others as an independent program, it is not suitable for my application scenario.

Solution:

Since the methods provided by netizens are not applicable, you can only find methods according to your own scenarios.
There is no problem in using cv2 in the python environment where the program is located. If I use cv2 in the environment directly, it should be able to solve my problem.
Through pycharm, I open cv2.__init__.py and jump to .cv2 again.

Note that in the python virtual environment where the program runs, the jump is successful, cv2.cv2.__init__.py is opened, and the cv2 library of time isThere is no such file.


Open cv2.cv2.__init__.pyThe directory where is located, which does not exist under the cv2 folder.Compare the differences between the cv2 folder used in the program operation and the files in the cv2 library file directory.

  • cv2 library:
  • The cv2 folder in the virtual environment where the program runs:
    Copy the cv2 file in the environment to the cv2 library packaged by the program, overwrite the duplicated content, and run the program again.The program runs successfully.

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved