-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False Positive import-error for tensorflow #2603
Comments
Can you try with |
@PCManticore I tried but nothing changed. |
I have the same problem too, placing some .py file under the same directory, I am using VSCode, where clicking into the module works well. |
--extension-pkg-whitelist=tensorflow also failed with some false positive E1101 of protobuf |
@AndyHuang0000 I had the same problem, did you ever find a fix? |
I get the same behaviour with tensorflow version 1.12. Pylint works fine with tensorflow 1.11 though. |
I updated to Tensorflow 1.13.0rc2 and this issue started occurring. Python version: 3.7.1 Pylint version: 2.2.2 There were no issues at Tensorflow version 1.12.0. and Python version 3.6.5 I tried to whitelist EDIT: Found the workaround by adding the following line to pylintrc:
|
Same issue with the following versions using vscode 1.31.1 w/virtualenv When I installed tensorflow globally (not just inside the virtualenv) it resolved the issue |
|
@bersbersbers You can try with |
|
The problem is that See this file which will be installed as A solution would be a pylint plugin which dynamically adds everything from tensorflow_core to tensorflow or to make pylint understand this redirection. |
@Flamefire thanks for the comment. It sounds to me like we could add an astroid transform for |
Sure. Something like generating a (faked) list of Could you create such a "brain" (or what it is called)? |
I created a plugin which seems to work:
@PCManticore If this code looks correct, it can be added as a brain. |
@Flamefire I used your plugin and added in visual studio's settings.json, "python.linting.pylintArgs": ["--load-plugins,pylint_tensorflow", ]. Unfortunately the modules are not recognized in visual studio, such as from tensorflow.keras.optimizers import Adam. I am using Tensorflow 2.0. However my code runs fine. |
I tested it from command line where it seemed to work. Maybe you are running into an intellisense issue and not the linter? See tensorflow/tensorflow#32982 (comment) Also: It should be: |
@Flamefire Thanks for providing the pylint plugin for tensorflow. I tested it and recognized, that the |
It sounds to me that @Flamefire 's PR works well in most cases, at least it gets rid of the |
Related TF issue: tensorflow/tensorflow#32982 --> Will probably be fixed in next 2.x release |
The plugin shown @Flamefire does not work for me. I installed the plugin and made sure that it is actually run by pylint (by temporarily adding a print statement). But when I run pylint, I still get the error. My code (runs with no errors):
Pylint call:
Software used:
|
For me, using |
I am having a similar issue with the line:
The following does seem to work for me, though I guess it's an internal namespace, so not ideal...
Because I think this namespace is probably a re-exposing of another namespace, it wouldn't surprise me if there is extra trickery going on for this one specifically. However, here is a way to easily reproduce any of the problems above with docker:
|
Is there any PR about this submitted to |
TF no longer uses a virtual pip package. Is this still an issue on latest TF? |
I can still reproduce this w/ tensorflow==2.5.0, pylint==2.8.3, and astroid==2.5.6:
Edit: Maybe that's more related to #3613. I can verify that this occurs w/ many/most(?) tensorflow calls. |
Seems like the brain from @Flamefire (#2603 (comment)) is not integrated yet in astroid but it could be. |
As of October 2023,
|
Can confirm, the problem still exists. The following minimal FROM python:3.11.6
RUN pip install tensorflow==2.15.0 keras==2.15.0
RUN pip install pylint==3.0.2
RUN echo "from tensorflow.keras import Model" > main.py
RUN pylint main.py
And replacing |
Steps to reproduce
bug.py
write the following code:pylint bug.py
Current behavior
The linter raises an error
Unable to import 'tensorflow.estimator
, but running the script everything works fine.Expected behavior
No error should have been raised.
pylint --version output
The text was updated successfully, but these errors were encountered: