如何在 raspbian 中将 pyinstaller 与 opencv 一起使用?

how use pyinstaller with opencv in raspbian?

我在 raspbian 中写了这个 python 脚本 "mycv.py":

import cv2 as cv

并调试 运行 currectly。然后我使用 pyinstaller 来制作可执行文件。 但是当 运行 终端中的文件时。它有错误:

Traceback (most recent call last):
  File "mycv.py", line 1, in <module>
    import cv2 as cv
  File "/usr/local/lib/python3.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "cv2/__init__.py", line 89, in <module>
  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.
[28400] Failed to execute script mycv

感谢任何帮助

经过大量调试,我找到了以下解决方案:

  1. 获取OpenCV的路径

    导入cv2 print(cv2.file) # /usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.so

  2. 通过pyinstaller编译时添加此路径

    pyinstaller main.py -n myApp --paths="/usr/local/lib/python3.6/dist-packages/cv2/python-3.6"

我希望这对其他人也有帮助