Closed born2discover closed 2 weeks ago
I don't think this is a bug in pyright. It appears to be a problem with your configuration or shell environment.
The log indicates that when pyright shell execs python3
and runs the script to extract the sys.paths
, it receives the following paths:
> [Info - 16:46:41] Received 4 paths from interpreter
> [Info - 16:46:41] file:///usr/lib/python3.11
> [Info - 16:46:41] file:///usr/lib/python3.11/lib-dynload
> [Info - 16:46:41] file:///app/lib/python3.11/site-packages
> [Info - 16:46:41] file:///home/eugene/.cache/pypoetry/virtualenvs/imexp-CA8YYaZW-py3.11/lib/python3.11/site-packages
Those are the paths pyright will use for import resolutions.
That's different from what you're seeing when you manually run the script. That means there's a difference between the shell environment used when pyright is running versus the shell environment that you're using when you run the script manually. You'll need to debug that issue on your system. I'm guessing that there's some environment variable that affects the python interpreter path or its behavior in determining which sys.paths to use.
I'm going to close the issue because I'm pretty confident this isn't a pyright bug, and I don't think there's anything actionable. If you need additional help and can provide more clues, feel free to post them here, and I'll do my best to assist in diagnosing the problem.
Red Hat family of distributions (Fedora et al.) differentiate between Python's
purelib
andplatlib
and those are thus set to different directories:<prefix>/lib
and<prefix>/lib64
respectively. Python packages are then installed in either of these.The current Pyright path finding logic does not seem to be aware of the existence of the
lib64/python(version)/site-packages
directory, and thus any and all modules installed in it can not be resolved by Pyright.Software versions Python 3.11.9 Pyright 1.1.369 (VS Code Extension)
Steps de reproduce On any Red Hat related distribution (this issue is being reported from Fedora 40):
sqlalchemy
version >= 2.0import sqlalchemy
in any python file.Import "sqlalchemy" could not be resolved Pyright (reportMissingImports)
error.Observations I noticed that Pyright already faced the same issue, and #1165 introduced a fix. However, after running Pyright with
verboseOutput = true
, I noticed the following (emphasis mine):Which seems to indicate that Pyright does not "see" the
lib64
directory. That led me togetPythonSearchPaths
and its subsequent call to_getSearchPathResultFromInterpreter
. The latter seems to call the python interpreter and retrieve relevant paths by executing a series of commands stored inextractSys
variable, which amounts to running the following python code:Running that on my system gives:
python311.zip
in/usr/lib64/
._getSearchPathResultFromInterpreter
function, "lib64" is turned into "lib"._getSearchPathResultFromInterpreter
but I do not see where the issue may lie..cache/
to the in-project.venv/
had no impact on the issue.Manual solution Adding
lib64
as an extra path in the configuration does seem to resolve the issue:extraPaths = ['./.venv/lib64/python3.11/site-packages']