-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Editable python package available from within Python but Pyright is raising reportMissingModuleSource
#3880
Comments
Yeah, this isn't a pyright issue. You'll need to debug the issue with your configuration. Pyright discovers the search paths by running the configured python interpreter and executing a small script that dumps out Make sure that you've activated your virtual environment prior to running pyright. |
Yes, I suspected that. But why is the package available from within python? Shouldn't pyright have access to all packages that the python interpreter has access to? PS: As stated above, I'm not running python from within a virtual environment. All packages are installed in the system's python. |
The issue was related to editable packages and setuptools. A temporary workaround suggested in the setuptools repro, is to add the environmental variable |
@erictraut Are you sure it's noting wrong with how pyright detects installed editable packages? Setuptools has made some changes recently to it's editable installation hooks within the context of PEP 660. It shouldn't be necessary to use setuptool's legacy behavior to prevent pyright from raising As far as I understand, setuptool's new editable installation hooks doesn't add editable packages' paths to |
The new setuptools mechanism makes use of dynamic import hooks that work at runtime but are not discoverable by static analysis tools. The entire static analysis tooling community (including the authors of all of the Python type checkers) made it clear that this would break static analysis tools, but the setuptools folks went ahead and made the change anyway. Their decision is now causing pain for the big parts of the Python development community. PEP 660 is very problematic and IMO should not have never been accepted. We will need to find some solution, but in the meantime, our best suggestion is to fall back on setuptool's legacy behavior. |
I see, thanks for the explanation! |
reportMissingModuleSource
reportMissingModuleSource
Unless I'm missing something, it's quite easy to analyze this particular dynamic import hook in a fully static way. While not ideal, maybe it'd be a good workaround until the Python community comes up with something better? Especially because with tools like |
I'm developing on OS X from within a VSC devcontainer built from
mcr.microsoft.com/vscode/devcontainers/python:3.10
. I have a local Python package installed using Pipenv and aPipfile
:However, I'm using Pipenv to install the packages to the devcontainer's system Python by executing:
In other words, I'm not running Python from within a virtual environment within the devcontainer. Yesterday, when I rebuilt my container, Pylance suddenly reported my local Python package as missing by raising
reportMissingModuleSource
.For debugging, I also tested with Pyright 1.1.268 by executing
pyright --verbose
from the project's root folder witch gave me the following results:I noted that
search paths
didn't include the path tomypackage
. Previously, I think this have been the case. By executingpython3.10 -c "import sys; print('\n'.join(sys.path))"
I (think I) previously got:However, if I execute the command now, I get:
That is, the path for
mypackage
is not included anymore. This led me to conclude that Pyright wasn't the issue. However, if I try to importmypackage
from within Python, it works:This made me check if
mypackage
was present in one of the search paths, and it was:cd /usr/local/lib/python3.10/site-packages dir __editable__.mypackage-0.0.1.pth __editable___mypackage_0_0_1_finder.py mypackage-0.0.1.dist-info [...]
I'm not sure if Pyright is the problem here, but since
mypackage
is available from within Python, I decided to open the issue here.EDIT:
pip list
also correctly listsmypackage
and it's location:The text was updated successfully, but these errors were encountered: