How To Resolve 'import "django.contrib" Could Not Be Resolved From Source' In Vs Code?
Solution 1:
I had exactly the same problem and there are several solutions out there, but only @Neha's answer has brought me to the point. The problem here is really simple. VS Code uses your "main" Python interpreter, whereas you should use the one in your virtual environment for Django.
In other words, I have my main Python installation here:
c:\users\yourName\appdata\local\programs\python\python39
.
And my VS Code has pointed to exactly this interpreter. But my Django was installed in this path:
c:\users\yourName\source\vscode-repos\basic-app\backend-service\venvs\lib\site-packages
.
In order to solve it click on the
VS Code bar with Python Interpreter, you will then see a pop-up window. Choose + Enter interpreter path... then Find.... It will open File Explorer for you. Go to your virtual environment folder, where you have your Django installed (in my case it the vscode-repos\basic-app\backend-service\venvs folder), inside of it go to the Scripts
folder and pick python.exe, like this. And you are good to go!
Solution 2:
Select the python interpreter in which u have created the virtual environment. I got the same error and this solution worked. Attached a screenshot u can refer to that. https://i.stack.imgur.com/pCbuB.jpg
Solution 3:
If you are using VScode, click the python version on the bottom left corner and select the venv where you have installed the packages.
Solution 4:
Actually all of the answers were right , but what worked for me is:
- Type
pip show Django
in vsc terminal - Go to the path of intallation mentioned there
- It will be inside "lib" by default..go back to scripts
- Inside the scripts , there will be python .exe app
- Choose this as your interpreter (as per above answers)
Post a Comment for "How To Resolve 'import "django.contrib" Could Not Be Resolved From Source' In Vs Code?"