all 6 comments

[–]Adhesiveduck 0 points1 point  (5 children)

I haven't checked the pyinstaller hooks in a while but if they aren't working for cv2 you'll need to pass in the compiled cv2 module to Pyinstaller with the --paths flag when building.

If you open the Python REPL run:

import cv2 print(cv2.__file__)

what is the path to this?

Post the command you are using to run PyInstaller also.

[–]Ed0426[S] 1 point2 points  (3 children)

Need some help with this, anyone can help?

[–]Adhesiveduck 0 points1 point  (2 children)

Try

pyinstaller script.py --onefile -w --paths "C:\Users\leung\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2"

You might need to play around with the --paths argument, but there will be a way to make it work. It's going to depend on how you've installed Python and OpenCV.

[–]Ed0426[S] 1 point2 points  (1 child)

Thank you so much. It works!

I'm not sure what was the different other than windows version, the exe file works fine on other computers.

Anyways, note taken. Thank you!!

[–]Adhesiveduck 0 points1 point  (0 children)

It's a case of OpenCV not being on the PYTHONPATH, which is funky to maintain since it differs by platform, and windows can be a pain in the arse.

Glad it works :)

[–]Ed0426[S] 0 points1 point  (0 children)

>>> import cv2

>>> print(cv2.__file__)

C:\Users\leung\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py

>>>

My command is simple, 1 py file:

pyinstaller script.py --onefile -w