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

Pylance not finding venv modules what venv is active #4679

Closed
highghlow opened this issue Aug 2, 2023 · 8 comments
Closed

Pylance not finding venv modules what venv is active #4679

highghlow opened this issue Aug 2, 2023 · 8 comments
Assignees
Labels
user responded Was "waiting for user response" and they responded

Comments

@highghlow
Copy link

Environment data

  • Language Server version: 2023.7.40
  • OS and version: linux x64 (immutable)
  • Python version (and distribution if applicable, e.g. Anaconda): Python 3.11.3 (pacman, venv)
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: off

Code Snippet

import numpy # venv is selected, code runs without an error, but pylance reports reportMissingModuleSource
print(numpy.__doc__)

Repro Steps

  1. Create and activate a venv
  2. Install a package into the venv
  3. Write python code that uses that module

Expected behavior

Pylance should see that the venv is active and find the module

Actual behavior

Pylance reports reportMissingModuleSource

Logs

python-language-server-log.txt

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 2, 2023
@escummy
Copy link

escummy commented Aug 2, 2023

You can check from the terminal if that python3 interpreter version is the same python version selected in VSCode.

If you open terminal and type 'python3' you'll see your python version (python3 version is 3.11.3), then open your IDE and navigate until any current folder that related to python project, check the python version at the bottom right on VSCode for example (in my case the python version is also 3.11.3).


The solution could be changing or switching Visual Studio Code Python Version from 3.11.3 to 3.9.12 (same with your python version on your computer) and it's solved.

Also, you can click on the interpreter version at the bottom left corner of the screen (VSCode) and it should show a dropdown menu with a list of the available and selected python interpreter, click on add interpreter path and paste the path to the python interpreter with all the required modules installed and click enter.


Originally, I tried to install numpy by the following command.

sudo apt-get install python3-numpy

Numpy was installed successfully as stated in the terminal and the problem is still there, but when I try to install numpy by the following command, the problem solved.

pip install numpy

I hope this can help.

@StellaHuang95
Copy link
Contributor

This message means that you don't have numpy installed in the Python environment that is currently selected. From reading your logs, the interpreter you have selected appears to be 3.10, which is different from the python version described in the issue. Could you check if that's the interpreter you've installed numpy into? If you look at the bottom right corner of the window, you should see which environment is selected.
image

You can also refer to this guide on selecting your environment. https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

@StellaHuang95 StellaHuang95 added waiting for user response Requires more information from user and removed needs repro Issue has not been reproduced yet labels Aug 3, 2023
@highghlow
Copy link
Author

highghlow commented Aug 3, 2023

This is really strange. The Python interpreter selected is 3.10.11 ('.venv': venv), but if I run the python executable from the venv, it says 3.11.3
image
And when I open a new terminal, vscode automatically selects the venv with numpy and python 3.11.3

@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 Aug 3, 2023
@StellaHuang95
Copy link
Contributor

You have Setting pythonPath for service "MQTTSmartHome": "/mnt/disk/Projects/Hobby/MQTTSmartHome/venv/bin/python" in your logs. Please refer to this guide on selecting your environment. https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

@highghlow
Copy link
Author

You have Setting pythonPath for service "MQTTSmartHome": "/mnt/disk/Projects/Hobby/MQTTSmartHome/venv/bin/python" in your logs. Please refer to this guide on selecting your environment. https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

I was working in venvbug whan reproducing the issue. There the venv is properly selected. SmartHome is unrelated to the issue

@mg-takuma-katanosaka
Copy link

I hit same issue.

@mg-takuma-katanosaka
Copy link

I hit same issue.

I've changed pre-release version because I expected to fix this issue. I look fixing to me.

@StellaHuang95
Copy link
Contributor

Hi there, can you verify if the problem still persists using the latest pylance? The reportMissingModuleSource diagnostic happens when a type stub is found, but the module source file was not found, indicating that the code may fail at runtime when using this execution environment. So you should be seeing the error if you have the package installed in your activated environment. Please reopen the issue if it still persists. Thanks!

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

4 participants