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

Installed pip package is not resolved by Pylance #6669

Open
anupamdialpad opened this issue Nov 15, 2024 · 4 comments
Open

Installed pip package is not resolved by Pylance #6669

anupamdialpad opened this issue Nov 15, 2024 · 4 comments
Assignees
Labels
user responded Was "waiting for user response" and they responded

Comments

@anupamdialpad
Copy link

Environment data

  • Pylance version: v2024.11.2
  • OS and version: macOS 15.0.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.11

Repro Steps

Image

Expected behavior

Pylance should be able to read installed pip packages under a virtual environment

Actual behavior

import pip packages under a virtual environment are not resolved by pylance

Logs

Here is the log link for that

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Nov 15, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Nov 15, 2024

Thanks for the issue.

According to the log, this is the current interpreter you have set:

/Users/anupamghosh/workspace/venv/servers/bin/python

Is that where the package is installed? How did you pick your interpreter? The UI you're showing in the screenshot isn't the normal UI for picking one.

Here's the log output for Pylance failing to find the pytz package:

2024-11-15 13:27:34.253 [info] [Info  - 13:27:34] (10460) Could not resolve source for 'pytz' in file '/Users/anupamghosh/workspace/dialpad/firespotter/fst2/frontend/api/sip_viewer.py'
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Looking in root directory of execution environment 'file:///%3Cdefault%20workspace%20root%3E'
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Attempting to resolve using root path 'file:///%3Cdefault%20workspace%20root%3E'
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Looking in extraPath 'file:///Users/anupamghosh/workspace/dialpad/firespotter/fst2'
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Attempting to resolve using root path 'file:///Users/anupamghosh/workspace/dialpad/firespotter/fst2'
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Finding python search paths
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Executing interpreter: '/Users/anupamghosh/workspace/venv/servers/bin/python'
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Skipping '/Users/anupamghosh/.pyenv/versions/3.11.4/lib/python311.zip' because it is not a valid directory
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)   Received 3 paths from interpreter
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)     file:///Users/anupamghosh/.pyenv/versions/3.11.4/lib/python3.11
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)     file:///Users/anupamghosh/.pyenv/versions/3.11.4/lib/python3.11/lib-dynload
2024-11-15 13:27:34.254 [info] [Info  - 13:27:34] (10460)     file:///Users/anupamghosh/workspace/venv/servers/lib/python3.11/site-packages
2024-11-15 13:27:34.255 [info] [Info  - 13:27:34] (10460)   Looking in python search path 'file:///Users/anupamghosh/.pyenv/versions/3.11.4/lib/python3.11'
2024-11-15 13:27:34.255 [info] [Info  - 13:27:34] (10460)   Attempting to resolve using root path 'file:///Users/anupamghosh/.pyenv/versions/3.11.4/lib/python3.11'
2024-11-15 13:27:34.255 [info] [Info  - 13:27:34] (10460)   Looking in python search path 'file:///Users/anupamghosh/.pyenv/versions/3.11.4/lib/python3.11/lib-dynload'
2024-11-15 13:27:34.255 [info] [Info  - 13:27:34] (10460)   Attempting to resolve using root path 'file:///Users/anupamghosh/.pyenv/versions/3.11.4/lib/python3.11/lib-dynload'
2024-11-15 13:27:34.255 [info] [Info  - 13:27:34] (10460)   Looking in python search path 'file:///Users/anupamghosh/workspace/venv/servers/lib/python3.11/site-packages'
2024-11-15 13:27:34.255 [info] [Info  - 13:27:34] (10460)   Attempting to resolve using root path 'file:///Users/anupamghosh/workspace/venv/servers/lib/python3.11/site-packages'

@StellaHuang95 StellaHuang95 added waiting for user response Requires more information from user and removed needs repro Issue has not been reproduced yet labels Nov 15, 2024
@anupamdialpad
Copy link
Author

How is virtualenv servers getting set? I have set the virtualenv to fst2. The screenshot in the bottom right shows,
that for the current file the virtualenv is fst2.

To set the virtualenv I used this flow ⌘ + shift + p -> > Python: select interpreter -> Selected the workspace folder fst2 -> gave the fst2 virtualenv path ~/workspace/venv/fst2/bin/python

Image

Following is my workspace configuration

{
    "folders": [
        {   
            "path": "servers"
        },  
        {   
            "path": "firespotter/prober"
        },  
        {   
            "path": "plivo"
        },  
        {   
            "path": "firespotter/fst2"
        },  
        {   
            "path": "kamailio"
        },  
        {   
            "path": "interactiveconsole"
        }   
    ],  
    "settings": {
        "python.analysis.extraPaths": ["/Users/anupamghosh/workspace/dialpad/firespotter/fst2"],
    }   
}

Below image shows my directory structure of the workspace
Image

@github-actions github-actions bot added user responded Was "waiting for user response" and they responded and removed waiting for user response Requires more information from user labels Nov 16, 2024
@StellaHuang95
Copy link
Contributor

It seems you're working in a multi-root workspace scenario. If you open the file where this package is being used and select the environment where the package is installed from the bottom-right corner of VS Code, does the error go away?
Image

@StellaHuang95 StellaHuang95 added waiting for user response Requires more information from user and removed user responded Was "waiting for user response" and they responded labels Nov 19, 2024
@anupamdialpad
Copy link
Author

pylance.could.not.resolve.mov

It still didn't work

@github-actions github-actions bot added user responded Was "waiting for user response" and they responded and removed waiting for user response Requires more information from user labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user responded Was "waiting for user response" and they responded
Projects
None yet
Development

No branches or pull requests

3 participants