-
Notifications
You must be signed in to change notification settings - Fork 894
Breaking changes in module loading v4.6.0.66 #676
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
Comments
Any suggestions welcome! |
Good day, why do you try to import the internal implementation module instead of the using $ python3 --version
Python 3.9.12
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install opencv-python-headless==4.6.0.66
$ python -c "import cv2; print(cv2.__version__)"
4.6.0
$ python -c "import cv2; print(cv2.putText)"
<built-in function putText> it is the same thing to do the following: |
I don't know how the cv2 is organized, by when you use
I don't know how the cv2 is organized, but when you use "import cv2", the PyCharm (and pylint) is not able to detect the members of cv2 , so it is giving warning for any operation of cv2. The solution is to use 'from cv2 import cv2' at the beginning of the code. Looks like the new version (4.6.066) changes the packaging of cv2, making 'from cv2 import cv2' no longer valid. |
Chiming in to improve searchability!
I have allow-listed cv2 as an extension package and still get a pylint error with the new version:
This issue was not present in |
Another pycharm user has to pin the version to |
Potentially related: #689 |
This issue is also bothering me |
The best way to fix autocomplete for a compiled package is to distribute a It's possible that type stubs could be generated automatically by mypy's stubgen module. |
There is activity on type stubs generation for OpenCV, but it's frozen today: they guys are very busy with main job: opencv/opencv#20370 |
This problem is still valid for opencv 4.7.0 if build it from source I have a folder If I call If I call from without |
crossposts:
this "from cv2 import cv2" nonsense is wrong. only pycharm users do it. stop doing it. it's wrong. |
@crackwitz you are posting the same 0 useful answer everywhere.
Let’s take a simple example with some dumb python module with only one function:
Contents of module:
Now let’s run it with the same python import rules:
Now, please, tell me, why it supposed to fail and why it worked with opencv 4.5.5? How I supposed to properly import With 4.5.5 working solution was
|
To add as to why it's a problem in the first place and we can't "just import cv2". Not being able to import cv2.cv2 also breaks non-static library analyzing tools. An obvious example is mypy's stubgen/stubtest, but it wouldn't be the only one. |
Just invalid usage. Agreed with @crackwitz So initial request and this issue are "invalid". @banderlog Your example is not correct as you can't do that for any(!) python module. There are no such obligations on the internal structure from OpenCV Python Bindings which you assumed. |
ok, the workaround is: # __init__.py of `foo_cv2` module with `cv2.so` within
import sys
import importlib
from importlib import resources
# get module path
path = resources.path(package='foo_cv2', resource="").__enter__()
# add it to PYTHONPATH
sys.path.insert(0, str(path))
# load all stuff
from cv2 import *
# wildcard import above does not import "private" variables like __version__
globals().update(importlib.import_module('cv2').__dict__) And usage will be @alalek ok, how it supposed to be imported correctly? |
I believe one week is enough to find OpenCV Python samples code:
to see It this doesn't work, then there is a problem with used Python environment. Besides of strange approach of hacking...
You should not modify the first entry of If you want just to import cv2.so / cv2.pyd / etc, then just put that file into |
please help me, ~\anaconda3\lib\site-packages\cv2_init_.py in bootstrap() ~\anaconda3\lib\site-packages\cv2_init_.py in __load_extra_py_code_for_module(base, name, enable_debug_print) ~\anaconda3\lib\importlib_init_.py in import_module(name, package) ~\anaconda3\lib\site-packages\cv2\typing_init_.py in TypeError: 'numpy._DTypeMeta' object is not subscriptable |
@alirezahamd254 That is a separate issue, unrelated to this issue. |
Expected behaviour
With opencv-python-headless-4.5.5.64 I was able to import opencv module into Python alike:
this way any related functionalities could be accessed, for example via
cv2.putText
.Actual behavior
Since yesterday, opencv-python-headless-4.6.0.66 gets pulled.
Any automated build pipelines now break with the error
Steps to reproduce
Issue submission checklist
opencv-python
The text was updated successfully, but these errors were encountered: