Skip to content
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

OpenCV vs Pylint - E0611:no-name-in-module - #9566

Open
Senja20 opened this issue Apr 25, 2024 · 3 comments
Open

OpenCV vs Pylint - E0611:no-name-in-module - #9566

Senja20 opened this issue Apr 25, 2024 · 3 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library

Comments

@Senja20
Copy link

Senja20 commented Apr 25, 2024

Bug description

I have an issue with PyLint and OpenCV. Whenever I import something from openCV I get the following error Pylint (E0611:no-name-in-module). Why doesn't it see the models in the cv2 library, as it does with other libraries?

Configuration

No response

Command used

pylint $(git ls-files '*.py')

Pylint output

************* Module utils.process_video
YOLO-detect-buoys\utils\process_video.py:7:0: E0611: No name 'VideoCapture' in module 'cv2' (no-name-in-module)
YOLO-detect-buoys\utils\process_video.py:7:0: E0611: No name 'destroyAllWindows' in module 'cv2' (no-name-in-module)
YOLO-detect-buoys\utils\process_video.py:7:0: E0611: No name 'imshow' in module 'cv2' (no-name-in-module)
YOLO-detect-buoys\utils\process_video.py:7:0: E0611: No name 'polylines' in module 'cv2' (no-name-in-module)
YOLO-detect-buoys\utils\process_video.py:7:0: E0611: No name 'waitKey' in module 'cv2' (no-name-in-module)

------------------------------------------------------------------
Your code has been rated at 6.84/10 (previous run: 6.84/10, +0.00)

Behavior

This is the resulting behavior:
image

Pylint version

pylint 3.1.0
astroid 3.1.0
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)]

OS / Environment

Windows 11 23H2, Powershell

Additional dependencies

opencv-python==4.9.0.80
packaging==24.0
pafy==0.5.5
pandas==2.2.1
pillow==10.2.0
pluggy==1.4.0
psutil==5.9.8
py-cpuinfo==9.0.0
pycryptodomex==3.20.0
pyparsing==3.1.2
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-magic==0.4.27
@Senja20 Senja20 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 25, 2024
@UlrichEckhardt
Copy link
Contributor

I can reproduce that on Ubuntu 22.04 with Python 3.10.12. As a test file, I'm using

import cv2
cv2.VideoCapture

The steps for setup are:

mkdir issue9566
cd issue9566/
python3 -m venv pyenv
source pyenv/bin/activate.fish
pip install --upgrade pip setuptools
pip install pylint==3.1.0
pip install opencv-python==4.9.0.80
python demo.py # no output, in particular no errors!
pylint --verbose demo.py 

This produces the following output

No config file found, using default configuration
************* Module demo
demo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
demo.py:2:0: W0104: Statement seems to have no effect (pointless-statement)
demo.py:2:0: E1101: Module 'cv2' has no 'VideoCapture' member (no-member)

---------------------------------------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 8.80/10, -8.80)
Checked 1 files, skipped 1 files

I looked into cv2 a bit and found this:

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> print(cv2.__all__)
[]
>>> 'VideoCapture' in dir(cv2)
True
>>> cv2.VideoCapture
<class 'cv2.VideoCapture'>

Looking at https://stackoverflow.com/a/64130/1968182, an empty or partial __all__ is not per-se a bug, though I'm no expert on the topic of Python modules. I guess this isn't just about OpenCV, but about exported names that are not part of __all__.

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 1, 2024
@Pierre-Sassoulas
Copy link
Member

Thank you for triaging @UlrichEckhardt, this is probably an issue with pylint not understanding python code that is "too dynamic" or C code inside OpenCV. Could require an astroid brain or an evolution in astroid to understand a particular dynamic code construct.

@UlrichEckhardt
Copy link
Contributor

I just tried to reproduce this in three ways:

  1. A single module file
  2. A single init.py file in a directory
  3. An init.py file which imports a name from another module file in that dir

In all three cases, __all__ was explicitly set to an empty list. In all three cases, I couldn't find any misbehaviour on pylint's part, so it may be specific to binary modules indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Lib specific 💅 This affect the code from a particular library
Projects
None yet
Development

No branches or pull requests

3 participants