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

Conda environment folders are not recognized as virtual environments #5191

Closed
rchiodo opened this issue Dec 1, 2023 Discussed in #5143 · 5 comments
Closed

Conda environment folders are not recognized as virtual environments #5191

rchiodo opened this issue Dec 1, 2023 Discussed in #5143 · 5 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@rchiodo
Copy link
Contributor

rchiodo commented Dec 1, 2023

Discussed in #5143

Originally posted by Ritesh313 November 24, 2023
I'm getting "<module_name>"is not accessed warnings from Pylance in my python file while importing all the stdlib modules.
The warning description just says:
conda_env_location/lib/python3.9/<module_name>.py" is overriding the stdlib module "<module_name>"

I have my anaconda environment selected as my interpreter in VS code. I know it's just a warning and not interrupting my code, but I would just like to know if I have something setup wrong. Please let me know if I should provide some other information for this.

Modules which have this warning: datetime, random, typing, argparse
Platform: VS code
Environment: Conda
Python version: 3.9.7

Here's a screenshot of the warning:
image

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Dec 1, 2023
@rchiodo
Copy link
Contributor Author

rchiodo commented Dec 1, 2023

More details, the virtual environment is on a file share in a linux environment.

@rchiodo
Copy link
Contributor Author

rchiodo commented Dec 1, 2023

As a workaround you can disable the warning for now like so:

    "python.analysis.diagnosticSeverityOverrides": {
        "reportShadowedImports": "none"
    }

@rchiodo
Copy link
Contributor Author

rchiodo commented Dec 1, 2023

I can reproduce this in a conda enviroment if I open the 'envs' folder:

image

We don't detect conda environments as virtual environments because they don't have a bin\activate or Scripts\activate file.

We could probably detect this situation, but I don't think this is very common. Most of the time the env folder is tucked away under the home directory.

@rchiodo rchiodo changed the title "<module_name>" is not accessed Pylance warning "<module_name>" is not accessed Pylance warning when putting Conda environment folders in the workspace Dec 1, 2023
@rchiodo rchiodo changed the title "<module_name>" is not accessed Pylance warning when putting Conda environment folders in the workspace Conda environment folders are not recognized as virtual environments Dec 5, 2023
@rchiodo rchiodo added bug Something isn't working and removed needs repro Issue has not been reproduced yet labels Dec 5, 2023
@msegado
Copy link

msegado commented Feb 6, 2024

We could probably detect this situation, but I don't think this is very common. Most of the time the env folder is tucked away under the home directory.

I do know there are also up-and-coming tools like Pixi that prefer to put Conda envs in a project subfolder, so it may become more common in the future. Pixi stores things in {project_root}/.pixi/ though, so it's ignored by Pylance (which excludes **/.* paths by default) and doesn't cause issues.

For anyone else who likes to put Conda envs in a .gitignored subfolder of their projects (like me!), Pylance will happily ignore it as long as you name your subfolder something like .env/ =)

@rchiodo rchiodo added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Apr 1, 2024
@debonte debonte added fixed in next version (pyright) A fix has been implemented and will appear in an upcoming version fixed in next version (main) and removed fixed in next version (main) A fix has been implemented and will appear in an upcoming version fixed in next version (main) fixed in next version (pyright) A fix has been implemented and will appear in an upcoming version labels Apr 4, 2024
@debonte
Copy link
Contributor

debonte commented Apr 4, 2024

This issue has been fixed in prerelease version 2024.4.100, which we've just released. You can find the changelog here: CHANGELOG.md

@debonte debonte closed this as completed Apr 4, 2024
@debonte debonte added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed fixed in next version (main) labels Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants