Home > OS >  Importing python modules in vscode
Importing python modules in vscode

Time:12-14

Recently downloaded vscode on macOS, but I seem unable to import any python modules. I've made sure I'm using a python3 interpreter but can't find the problem. For example:

import numpy as np

returns

ModuleNotFoundError: No module named 'numpy'

and similarly for any other modules:

import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

I have downloaded homebrew although I don't understand what it is (I'm a physicist not a programmer) and so far spent a few hours trying to figure it out. Any help would be great.

CodePudding user response:

Those two modules are third-part modules that need to be downloaded. The easiest/most common way to download is to use pip, which is a python module that should have come with your python install.

From the command line, run a python3 -m pip install numpy matplotlib. That will call python using the module pip, with the pip command 'install numpy maplotlib' (you can call them one-at-a-time if you like).

Once they are installed, you should be able to import them as you attempted above.

CodePudding user response:

This happened to me before when I tried to download the flask module,all I did was restart my vs-code and everything was working

  • Related