Skip to content
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

Import resolution not respecting virtual environments #5943

Closed
ITProKyle opened this issue Sep 14, 2023 · 11 comments · Fixed by #5946
Closed

Import resolution not respecting virtual environments #5943

ITProKyle opened this issue Sep 14, 2023 · 11 comments · Fixed by #5946
Assignees
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@ITProKyle
Copy link

ITProKyle commented Sep 14, 2023

Describe the bug

When updating from 1.1.321 to 1.1.327, I am receiving reportMissingImports in all of my projects. I use poetry to manage python dependencies & virtual environment for both local deployment and pipeline execution.

EDIT: Tested with 1.1.326 and this bug is not present so it was introduced in 1.1.327

When running pyright, I run npm exec --no -- pyright --venvpath ./ with venv = ".venv" set in my pyproject.toml. I typically (especially in pipeline executions) do not activate the virtual environment prior to running pyright.

For all versions prior to 1.1.327, this worked fine. However, after updating pyright raises reportMissingImports for all dependencies that exist only in my virtual environment (e.g. pytest for my tests).

If I activate my python virtual environment prior to running pyright, it is able to resolve the imports correctly.

All repos I am seeing this in are private or I would provide a link to an example.

VS Code extension or command-line

Identified via command line.

@ITProKyle ITProKyle added the bug Something isn't working label Sep 14, 2023
@erictraut
Copy link
Collaborator

@rchiodo, I'm guessing this is related to your real path changes. Could you investigate?

@rchiodo rchiodo self-assigned this Sep 14, 2023
@rchiodo
Copy link
Collaborator

rchiodo commented Sep 14, 2023

Sure let me try to reproduce the problem. It sounds like it should reproduce with a pip venv too.

@rchiodo
Copy link
Collaborator

rchiodo commented Sep 14, 2023

Yeah, I can reproduce. I think it has something to do with translating paths on the command line.

If you put the 'venvFolder' into the pyrightconfig.json, I believe that will fix the problem temporarily.

At least if I have this in pyrightconfig.json, I can't reproduce:

{
   "venv": ".venv",
   "venvPath": "."
}

But with this:

{
   "venv": ".venv",
}

and passing --venvpath on the command line, then it reproduces.

@erictraut erictraut reopened this Sep 14, 2023
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Sep 14, 2023
@rchiodo
Copy link
Collaborator

rchiodo commented Sep 14, 2023

Oh whoops, I shouldn't put 'Fixed' in the titles of the PRs.

@fzakaria
Copy link

I am seeing this also on 1.1.327 as well (upgraded from 1.1.325) -- doesn't matter if i specify --venvpath or --pythonpath

@fzakaria
Copy link

Seems like it has to do something with symlinks ?
FWIW I also use Pyright with Nix (https://nixos.org), specifically poetry2nix (https://github.com/nix-community/poetry2nix)
which creates a symlink tree of a site-packages directory (see below)

❯ ls -l /nix/store/kkr5h7331csxybk2fvzrqzdrv6gfrhra-python3-3.10.12-env/lib/python3.10/site-packages | head
dr-xr-xr-x   - fmzakari  1 Jan  1970 __pycache__
lrwxrwxrwx 114 fmzakari  1 Jan  1970 _black_version.py -> /nix/store/19635i1dahlgnp6hqav96hzf7yn49cr4-python3.10-black-23.9.1/lib/python3.10/site-packages/_black_version.py
lrwxrwxrwx 117 fmzakari  1 Jan  1970 _distutils_hack -> /nix/store/hxqf8h7yq8d8nchhkac9lqihdqj9h0ml-python3.10-setuptools-67.4.0/lib/python3.10/site-packages/_distutils_hack
lrwxrwxrwx 104 fmzakari  1 Jan  1970 _pytest -> /nix/store/g063887s1sa392l2i15s2lr2fqxw3c4i-python3.10-pytest-7.4.2/lib/python3.10/site-packages/_pytest
lrwxrwxrwx 130 fmzakari  1 Jan  1970 _sysconfigdata__linux_x86_64-linux-gnu.py -> /nix/store/bc45k1n0pkrdkr3xa6w84w1xhkl1kkyp-python3-3.10.12/lib/python3.10/site-packages/_sysconfigdata__linux_x86_64-linux-gnu.py
lrwxrwxrwx 102 fmzakari  1 Jan  1970 apsw -> /nix/store/jvliqw7rxkwdf2hdkzfvp3gq4ksrdckb-python3.10-apsw-3.43.1.0/lib/python3.10/site-packages/apsw
lrwxrwxrwx 121 fmzakari  1 Jan  1970 apsw-3.43.1.0.dist-info -> /nix/store/jvliqw7rxkwdf2hdkzfvp3gq4ksrdckb-python3.10-apsw-3.43.1.0/lib/python3.10/site-packages/apsw-3.43.1.0.dist-info
lrwxrwxrwx 102 fmzakari  1 Jan  1970 black -> /nix/store/19635i1dahlgnp6hqav96hzf7yn49cr4-python3.10-black-23.9.1/lib/python3.10/site-packages/black
lrwxrwxrwx 119 fmzakari  1 Jan  1970 black-23.9.1.dist-info -> /nix/store/19635i1dahlgnp6hqav96hzf7yn49cr4-python3.10-black-23.9.1/lib/python3.10/site-packages/black-23.9.1.dist-info
lrwxrwxrwx 103 fmzakari  1 Jan  1970 blackd -> /nix/store/19635i1dahlgnp6hqav96hzf7yn49cr4-python3.10-black-23.9.1/lib/python3.10/site-packages/blackd

@erictraut
Copy link
Collaborator

Yes, this is related to symlinks. There is already a fix in place, and it will be included in next week's pyright release. In the meantime, you can work around the issue by downgrading to 1.1.326. Apologies for the regression.

@fzakaria
Copy link

Thank you for the tool and the work.

@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.328, which I just published. It will also be included in a future release of pylance.

@mattiacolombomc
Copy link

mattiacolombomc commented Apr 22, 2024

This is still present today. Could you please help?

Just so you know, the script runs perfectly.

CleanShot 2024-04-22 at 17 51 59@2x
CleanShot 2024-04-22 at 17 54 56@2x

@erictraut
Copy link
Collaborator

@mattiacolombomc, this issue has been fixed and closed. If you're experiencing a similar issue, then it's different than the original. If you think that you are seeing a bug, please file a new issue with repro steps as described in the bug template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants