I have installed python version 3.7 and visual studio code latest version, after that i have created virtual environment and installed django and created Django project.
Whenever i am opening some file, its showing error like below
unresolved import 'django.contrib' unresolved import 'django.urls' Undefined variable: 'path' Undefined variable: 'admin'
Below are the paths of my application
1) Python : C:\Python\Python37-32\python.exe 2) Virtual environment created D:\django_projects\envs\py1\ 3) Django Project created D:\django_projects\p1\p1
Below are the things i have tried 1) Re Installing Python 2) Setting the Python Path in environment variable even i selected include in the path at the time of python installation 3) Re installing the VS Code 4) Tried commenting the "python.jediEnabled": false, in settings.json file in vs code, but it was giving different error unable to import django. 5)
unresolved import 'django.contrib' unresolved import 'django.urls' Undefined variable: 'path' Undefined variable: 'admin'

You did not select the virtual environment you installed Django into in VS Code (see the bottom-left corner for your screenshot where it says "Python 3.7.4 32-bit"; it would say "venv" or something if you were using a virtual environment). Try clicking on the interpreter in the status bar and then select your environment.
In my case, the error was:
unresolved import 'pydotplus' Python (unresolved-import)
And it was not a 64 bit vs. 32 bit issue. Instead, the wrong linting (because the code is running, and there is just wrong underlining in the editor) came from a needed extra python path in the json settings.
At best, following https://github.com/Microsoft/python-language-server/issues/887 and there the approach of HozcarAndres and the one after it.
//"python.pythonPath": "C:/Users/Admin/Anaconda3/python.exe",
"python.autoComplete.extraPaths": [
"C:/Users/Admin/Anaconda3/Lib/site-packages/",
... (you can add further pahts in this String array)
]
"python.pythonPath" is not needed because it is the already known default.
Or go to settings.json (Ctrl+Shift+P and search for it) and change it to
{
[many settings...],
[previous last line],
"python.pythonPath": "C:/Users/Admin/Anaconda3/**"
}
(or change the existing "python.pythonPath", though this is not there as a default)
Then, the packages like django which are only in the C:/Users/Admin/Anaconda3/Lib/site-packages/ will automatically be recognised by the linting, while as a default, the path is only C:/Users/Admin/Anaconda3/python.exe - not enough to "know" the site-packages.
And you cannot make a list of paths here, as only a single string can be entered.
In case the Python interpreter gets lost after this, you can newly assign the python interpreter. Go to the left bottom in the blue line and choose "Python 3.7..." interpreter again.
Any more settings on the linting are here: https://code.visualstudio.com/docs/python/linting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With