Import Errors in Python: No Module Named “Module_Name” For VS Code

Dilmi Kottachchi
Nerd For Tech
Published in
2 min readJun 2, 2021

--

You may have come across the dreaded import error in python like the one below:

No module named ----- 

This is actually a simple error you can fix in no time. This may usually be a simple fix you can make through Visual Studio Code.

Before anything I highly recommend you to work with a virtual environment like Anaconda to manage all your packages.

Firstly, open up visual studio code and in your terminal check whether you are in your virtual environment. You can move into your virtual environment by typing in ‘conda activate (virtual environment name)’. This is shown below.

But as you can see even though you have moved into your virtual environment, the python interpreter is still pointing to your base environment instead of your virtual environment. This is shown below.

If so hold ‘Ctrl+Shift+P’ in Windows or ‘Command+Shift+P’ in Mac to open up the context menu in Visual Studio Code. There search for ‘Python: Select Interpreter’

Here you have the option of selecting your python interpreter the project is currently pointing at. Since it was pointed to the conda base environment, you can go and select the virtual environment that you installed your packages for the project. In this case it ‘Python 3.9.2 64 bit (‘venv’: conda)’ as shown below.

Once you selected that, you will see that your interpreter has shifted to point to your virtual environment.

So there you have it. Once you run your project, everything will be working fine and no more import errors you will have to worry about.

Author: Dilmi Kottachchi

--

--