Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pyright cannot resolve the wandb module import, although it can resolve every other import. #787

Closed
oyarsa opened this issue Jul 3, 2020 · 4 comments
Labels
addressed in next version Issue is fixed and will appear in next published version

Comments

@oyarsa
Copy link

oyarsa commented Jul 3, 2020

Describe the bug
Pyright cannot resolve the wandb module import, although it can resolve every other import.

To Reproduce
I am using poetry, but running pyright directly from the command line (inside the venv) results in the same problem.

  • Start a new venv
  • Import the module wandb in a file, alongside any other installed dependency, say, sklearn
  • Run pyright (or pylance from VSCode)
  • Pyright appropriately resolves the sklearn import, but not wandb
  • Pyright gives the error error: Import "wandb" could not be resolved (reportMissingImports)

Expected behavior
Pyright can resolve the wandb import correctly

Screenshots or Code

Log from `pyright --verbose`

No configuration file found.
Search paths found for configured python interpreter:
  /usr/lib/python3.8
  /usr/lib/python3.8/lib-dynload
  /home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages
When attempting to get search paths from python interpreter:
  Executing python interpreter
  Skipping '/usr/lib/python38.zip' because it is not a valid directory
  Received 3 paths from interpreter
    /usr/lib/python3.8
    /usr/lib/python3.8/lib-dynload
    /home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages
stubPath /home/italo/dev/tmp/test/test/typings is not a valid directory.
Searching for source files
Found 3 source files
Could not import 'wandb' in file '/home/italo/dev/tmp/test/test/__init__.py'
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/wandb.py'
  Typeshed path not found
  Looking in root directory of execution environment '/home/italo/dev/tmp/test/test'
  Attempting to resolve using root path '/home/italo/dev/tmp/test/test'
  Partially resolved import with directory '/home/italo/dev/tmp/test/test/wandb'
  Looking in stubPath '/home/italo/dev/tmp/test/test/typings'
  Attempting to resolve using root path '/home/italo/dev/tmp/test/test/typings'
  Did not find file '/home/italo/dev/tmp/test/test/typings/wandb.pyi' or '/home/italo/dev/tmp/test/test/typings/wandb.py'
  Looking for typeshed path
  Looking for typeshed third_party path
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/wandb.py'
  Typeshed path not found
  Looking in python search path '/usr/lib/python3.8'
  Attempting to resolve using root path '/usr/lib/python3.8'
  Did not find file '/usr/lib/python3.8/wandb.pyi' or '/usr/lib/python3.8/wandb.py'
  Looking in python search path '/usr/lib/python3.8/lib-dynload'
  Attempting to resolve using root path '/usr/lib/python3.8/lib-dynload'
  Did not find file '/usr/lib/python3.8/lib-dynload/wandb.pyi' or '/usr/lib/python3.8/lib-dynload/wandb.py'
  Looking in python search path '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages'
  Attempting to resolve using root path '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages'
  Resolved import with file '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages/wandb/__init__.py'
Could not import 'wandb' in file '/home/italo/dev/tmp/test/test/run.py'
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/wandb.py'
  Typeshed path not found
  Looking in root directory of execution environment '/home/italo/dev/tmp/test/test'
  Attempting to resolve using root path '/home/italo/dev/tmp/test/test'
  Partially resolved import with directory '/home/italo/dev/tmp/test/test/wandb'
  Looking in stubPath '/home/italo/dev/tmp/test/test/typings'
  Attempting to resolve using root path '/home/italo/dev/tmp/test/test/typings'
  Did not find file '/home/italo/dev/tmp/test/test/typings/wandb.pyi' or '/home/italo/dev/tmp/test/test/typings/wandb.py'
  Looking for typeshed path
  Looking for typeshed third_party path
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/wandb.py'
  Typeshed path not found
  Looking in python search path '/usr/lib/python3.8'
  Attempting to resolve using root path '/usr/lib/python3.8'
  Did not find file '/usr/lib/python3.8/wandb.pyi' or '/usr/lib/python3.8/wandb.py'
  Looking in python search path '/usr/lib/python3.8/lib-dynload'
  Attempting to resolve using root path '/usr/lib/python3.8/lib-dynload'
  Did not find file '/usr/lib/python3.8/lib-dynload/wandb.pyi' or '/usr/lib/python3.8/lib-dynload/wandb.py'
  Looking in python search path '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages'
  Attempting to resolve using root path '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages'
  Resolved import with file '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages/wandb/__init__.py'
Could not import 'wandb' in file '/home/italo/dev/tmp/test/test/wandb/run-20200703_135936-2ixedkt7/code/run.py'
  Looking for typeshed stdlib path
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.7/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3.6/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/3/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/stdlib/2and3/wandb.py'
  Typeshed path not found
  Looking in root directory of execution environment '/home/italo/dev/tmp/test/test'
  Attempting to resolve using root path '/home/italo/dev/tmp/test/test'
  Partially resolved import with directory '/home/italo/dev/tmp/test/test/wandb'
  Looking in stubPath '/home/italo/dev/tmp/test/test/typings'
  Attempting to resolve using root path '/home/italo/dev/tmp/test/test/typings'
  Did not find file '/home/italo/dev/tmp/test/test/typings/wandb.pyi' or '/home/italo/dev/tmp/test/test/typings/wandb.py'
  Looking for typeshed path
  Looking for typeshed third_party path
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/3/wandb.py'
  Attempting to resolve using root path '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3'
  Did not find file '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/wandb.pyi' or '/usr/lib/node_modules/pyright/dist/typeshed-fallback/third_party/2and3/wandb.py'
  Typeshed path not found
  Looking in python search path '/usr/lib/python3.8'
  Attempting to resolve using root path '/usr/lib/python3.8'
  Did not find file '/usr/lib/python3.8/wandb.pyi' or '/usr/lib/python3.8/wandb.py'
  Looking in python search path '/usr/lib/python3.8/lib-dynload'
  Attempting to resolve using root path '/usr/lib/python3.8/lib-dynload'
  Did not find file '/usr/lib/python3.8/lib-dynload/wandb.pyi' or '/usr/lib/python3.8/lib-dynload/wandb.py'
  Looking in python search path '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages'
  Attempting to resolve using root path '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages'
  Resolved import with file '/home/italo/.cache/pypoetry/virtualenvs/test-Cf4rN2Qf-py3.8/lib/python3.8/site-packages/wandb/__init__.py'
/home/italo/dev/tmp/test/test/__init__.py
  3:8 - error: Import "wandb" could not be resolved (reportMissingImports)
/home/italo/dev/tmp/test/test/run.py
  2:8 - error: Import "wandb" could not be resolved (reportMissingImports)
/home/italo/dev/tmp/test/test/wandb/run-20200703_135936-2ixedkt7/code/run.py
  2:8 - error: Import "wandb" could not be resolved (reportMissingImports)
3 errors, 0 warnings 
Completed in 0.907sec

VS Code extension or command-line
This happens with Pylance 2020.6.1 and pyright 1.1.48

Additional context
What strikes me as odd is that pyright can find the module (Resolved import with file [...]), but for some reason, it still doesn't resolve it.

@erictraut
Copy link
Collaborator

Thanks for the bug report.

I'm not able to repro the problem as described. Perhaps there are additional details. What form of an import statement are you using in your code? Are you using import wandb or from wandb import x?

Here's what I see when I try to repro:

Screen Shot 2020-07-03 at 10 27 20 AM

@erictraut erictraut added the question Further information is requested label Jul 3, 2020
@oyarsa
Copy link
Author

oyarsa commented Jul 3, 2020

Thank you for replying this fast. Here's... something:

ss

The file a.py only contains the import. When I run pyright on the same directory, no problem. When I run at the root of the project, there's the problem. In fact, I just found out (not on the screenshot), that any other directory but the project root works.

A few minutes of testing later...

Okay, I think I figured this out: creating a folder with the same name as the module in the working directory creates this error. The initial scenario had a wandb folder at the project root. I tested with a clean project, and the same happens: pyright gives this error if there's a folder with the same name as module in the directory where I call the program.

image

test.py is just

import wandb
print(wandb.__version__)

@erictraut erictraut removed the question Further information is requested label Jul 4, 2020
@erictraut
Copy link
Collaborator

Thanks for the additional clues. This is a bug in Pyright's import resolution code. It should always favor a third-party library import if a local import can't be found. A fix will be included in the next version of Pyright.

@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jul 4, 2020
@erictraut
Copy link
Collaborator

This is addressed in Pyright 1.1.49, which I just published.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
addressed in next version Issue is fixed and will appear in next published version
Projects
None yet
Development

No branches or pull requests

2 participants