E0401:Unable to import 'django.db'

Viewed 15278

So i'm studying python crashcourse and after finishing the basics I jumped to the django project.

I created a virtual env, installed django and created an app with manage.py startapp command.

I use Visual Studio Code, and the problem is when I go to models.py it gives an error that it's unable to find django.db module

unable to import error

Now I understand this is because of the file structure, which is as per my research the correct one, and I followed the book carefully, however i don't know how to fix this and I feel that i'm missing something.

This is my file structure for the virtual environment

file structure

Any idea how to fix it ? :)

Thanks in advance

5 Answers

Thank you Incognos !

To be more specific The solution was :

enter "code ." in the terminal and then a new VS opens. Ctrl+Shift+P -> Select Interpreter select the environment that starts with ./env or .\env run Ctrl+Shift+` to activate it

it happens because pylint is installed outside your virtual environment. So install pylint inside virtual environment with this command (pip install pylint).

Note: If you're using Visual Studio Code - Insiders you'll use code-insiders . instead of the code . command.

Then, a new window will open and you can set your virtual environment interpreter there.

Reference: https://github.com/Microsoft/vscode/issues/6627

in my case, the problem was solved by opening VS-Code in the directory where virtualenv is located.

Related