skip to Main Content

I’m a linux user (zorin-os distro) using the flatpak version of Visual Studio Code. I have configured my interpreter as needed.

I’m trying to use numpy and matplotlib that I’ve installed with pip but it seems like Pylance cannot detect them. I can run my program normally with the interpreter (example below) but I have 2 distinct warnings.

import numpy as np
import matplotlib.pyplot as plt

X = np.linspace(-2,2,100)

plt.plot(X,X**2)
plt.show()

The first warning is reportMissingImports for Numpy and the second is reportMissingModuleSource for matplotlib. The strange thing about these warnings is that the first one is false because I can run my program correctly and the second is also false because, with Ctrl + Left clic on matplotlib, I can access the source.

So what is happening here ? The warning for matplotlib is not problematic because the intellisense is working fine but the warning for numpy make me unable to have intellisense for numpy commands which is really anoying.

Thanks for reading !

2

Answers


  1. Chosen as BEST ANSWER

    I solved my problem.

    First, I had a bug with my vscode Python interpreters that was fixed most likely by one of the latest update of zorin-os.

    Secondly, with my vscode interpreters now working correctly, i stopped using my native python interpreter and used the ones from vscode. I still had warnings but at least this time they were correct because I could not run the program.

    After that, I documented myself and understood that I had to create a virtual environment where I pip-installed the needed library and selected it as my interpreter and now everything works fine.

    So now everything is great but there is one thing bugging me out. Why can't I pip-install on global environments in vscode ? I know virtual environments are really great because it can be project specific but I'm not a professional programmer and a global environment would be sufficient.

    Anyway, thanks for reading !


  2. You can use command which python3 to get the path in which you’re python is installed.

    Then add the following codes to your settings.json(You can use shortcuts Ctrl+Shift+P and type Preferences: Open User Settings(JSON)):

    "python.defaultInterpreterPath": "path/to/your/python"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search