-
Notifications
You must be signed in to change notification settings - Fork 474
Import numpy in platform.py #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Import NumPy before OpenCV in platform.py to prevent import/segfault issues (FreeBSD & cross-platform safety)
|
Thanks for letting me know, I would be happy to upstream to avoid needing a patch! I can coordinate a new Python release with the fix as soon as possible (this should not affect the Windows distribution). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, has this caused any actual issues? We also import cv2 in __init__.py before this code has run:
PySceneDetect/scenedetect/__init__.py
Lines 21 to 30 in ad9d35d
| # OpenCV is a required package, but we don't have it as an explicit dependency since we | |
| # need to support both opencv-python and opencv-python-headless. Include some additional | |
| # context with the exception if this is the case. | |
| try: | |
| import cv2 as _ | |
| except ModuleNotFoundError as ex: | |
| raise ModuleNotFoundError( | |
| "OpenCV could not be found, try installing opencv-python:\n\npip install opencv-python", | |
| name="cv2", | |
| ) from ex |
That being said, if this does need to be done, I think the patch was applied incorrectly since it looks like numpy is imported after OpenCV is.
|
Hi! Thanks for taking a look. I have recently started maintaining this port, and I thought this was the reason why the patch was added earlier. Since OpenCV is being loaded earlier (as shown in the code), I will remove the patch as well. If any of the users reports any issues, we can revisit here again. |
Thank you! Feel free to reach out if you encounter any issues after removing the patch, happy to coordinate any fixes. Cheers. |
Import NumPy before OpenCV in platform.py to prevent import/segfault issues (FreeBSD & cross-platform safety)
On FreeBSD, importing OpenCV (cv2) before NumPy can blow up with errors like “numpy.core.multiarray failed to import” or even a segfault. The reason is that OpenCV relies on NumPy under the hood, so if NumPy hasn’t been loaded yet, things can go wrong.
FreeBSD Ports Tree already carries a patch that imports numpy to prevent this. Thought it would not be a bad idea to upstream this
https://github.com/freebsd/freebsd-ports/blob/main/multimedia/py-scenedetect/files/patch-scenedetect_platform.py