pi-top / pi-top-Python-SDK

pi-top's Python SDK (pitop package)
Apache License 2.0
27 stars 4 forks source link

Depend on numpy>1.19.5 when pip-installing #557

Closed jcapona closed 1 year ago

jcapona commented 1 year ago

Main changes

When pip installing a subpackage in Raspberry Pi OS, we used the already installed numpy package, version 1.19.5, which was the version we wanted to install. However, this error came up when trying to import cv2:

>>> import cv2
RuntimeError: module compiled against API version 0xf but this version of numpy is 0xd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.9/site-packages/cv2/__init__.py", line 8, in <module>
    from .cv2 import *
ImportError: numpy.core.multiarray failed to import

After reading this useful explanation, it seems that we need to use a newer version of numpy.

Note: This is not an issue when installing the subpackages using the deb files.

Manual testing tips

codecov[bot] commented 1 year ago

Codecov Report

Base: 45.90% // Head: 60.79% // Increases project coverage by +14.89% :tada:

Coverage data is based on head (d5e1755) compared to base (e291cd0). Patch coverage: 78.38% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## subpackages #557 +/- ## ================================================ + Coverage 45.90% 60.79% +14.89% ================================================ Files 120 138 +18 Lines 5916 6903 +987 ================================================ + Hits 2716 4197 +1481 + Misses 3200 2706 -494 ``` | Flag | Coverage Δ | | |---|---|---| | unittests | `60.79% <78.38%> (+14.89%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top) | Coverage Δ | | |---|---|---| | [packages/camera/pitop/camera/\_\_init\_\_.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9fX2luaXRfXy5weQ==) | `100.00% <ø> (ø)` | | | [packages/camera/pitop/camera/core/\_\_init\_\_.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL19faW5pdF9fLnB5) | `100.00% <ø> (ø)` | | | [...kages/camera/pitop/camera/core/cameras/\_\_init\_\_.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhbWVyYXMvX19pbml0X18ucHk=) | `100.00% <ø> (ø)` | | | [...s/camera/pitop/camera/core/cameras/camera\_types.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhbWVyYXMvY2FtZXJhX3R5cGVzLnB5) | `100.00% <ø> (ø)` | | | [...ra/pitop/camera/core/cameras/file\_system\_camera.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhbWVyYXMvZmlsZV9zeXN0ZW1fY2FtZXJhLnB5) | `84.00% <ø> (+58.00%)` | :arrow_up: | | [...mera/pitop/camera/core/capture\_actions/\_\_init\_\_.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhcHR1cmVfYWN0aW9ucy9fX2luaXRfXy5weQ==) | `100.00% <ø> (ø)` | | | [...camera/core/capture\_actions/capture\_action\_base.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhcHR1cmVfYWN0aW9ucy9jYXB0dXJlX2FjdGlvbl9iYXNlLnB5) | `88.88% <ø> (+27.77%)` | :arrow_up: | | [...top/camera/core/capture\_actions/capture\_actions.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhcHR1cmVfYWN0aW9ucy9jYXB0dXJlX2FjdGlvbnMucHk=) | `100.00% <ø> (ø)` | | | [...itop/camera/core/capture\_actions/generic\_action.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhcHR1cmVfYWN0aW9ucy9nZW5lcmljX2FjdGlvbi5weQ==) | `74.07% <ø> (+40.74%)` | :arrow_up: | | [...top/camera/core/capture\_actions/motion\_detector.py](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top#diff-cGFja2FnZXMvY2FtZXJhL3BpdG9wL2NhbWVyYS9jb3JlL2NhcHR1cmVfYWN0aW9ucy9tb3Rpb25fZGV0ZWN0b3IucHk=) | `80.48% <ø> (+56.09%)` | :arrow_up: | | ... and [239 more](https://codecov.io/gh/pi-top/pi-top-Python-SDK/pull/557/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top) | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pi-top)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

jcapona commented 1 year ago

Yeah, on the deb side, we're pretty much stuck with numpy 1.19.5 and opencv 4.5.1, and both of them work together okay.

If you pip install the same versions, sadly, they're not compatible with each other (module compiled against API version 0xf but this version of numpy is 0xd). My guess is that the version of opencv distributed via pypi was compiled using a different version of numpy compared to the one distributed via apt.

The main issue we need to solve here is to make sure that the version of numpy is >1.19.5, at least when pip-installing. The limitation on the version of opencv is not really necessary, since the latest version available in pypi, 4.6.0, is still compatible with the version of numpy that gets installed via pip, 1.23.0.