Describe the bug
Pyright is failing to find local modules that Python successfully imports.
To Reproduce
Make have a folder structure like so:
Where main.py is:
import mymodule
Expected behavior
Pyright detects mymodule and properly loads types for it.
VS Code extension or command-line
I am running 1.0.67 as a VSCode extension with Python 3.7.4.
The "code" directory in your example appears to contain a package, as evidenced by the presence of an __init__.py file. Packages are meant to be imported by top-level scripts or by other packages.
I replicated your example and wrote a simple top-level script root/test.py that imports the "code.main" module .
# test.py script
import code.main
When I run the test.py script, I receive an error ModuleNotFoundError: No module named 'mymodule'. So I think pyright is correct in flagging this as an error.
If you want to avoid the error, there are two solutions:
from .mymodule import X, Y, Z){
"executionEnvironments": [
{
"root": "code"
}
]
}
Thanks, I ended up going with the second option. I didn't see that executionEnvironments setting in the documentation.
Most helpful comment
The "code" directory in your example appears to contain a package, as evidenced by the presence of an
__init__.pyfile. Packages are meant to be imported by top-level scripts or by other packages.I replicated your example and wrote a simple top-level script
root/test.pythat imports the "code.main" module .When I run the test.py script, I receive an error
ModuleNotFoundError: No module named 'mymodule'. So I think pyright is correct in flagging this as an error.If you want to avoid the error, there are two solutions:
from .mymodule import X, Y, Z)