Visual Studio代码未解析的导入? [英] visual studio code unresolved import?
问题描述
我已经安装了python版本3.7和Visual Studio代码的最新版本,此后,我创建了虚拟环境并安装了django并创建了Django项目.
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
未解决的导入'django.contrib'未解析的导入'django.urls'未定义的变量:路径"未定义的变量:"admin"
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.exe2)创建虚拟环境D:\ django_projects \ envs \ py1 \3)创建Django项目D:\ django_projects \ p1 \ p1
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
以下是我尝试过的事情1)重新安装Python2)即使我选择在环境变量中设置Python路径时,也要在环境变量中设置Python路径3)重新安装VS Code4)尝试注释"python.jediEnabled":false,在vs代码的settings.json文件中,但是它给出了无法导入django的其他错误.5)
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)
未解决的导入'django.contrib'未解析的导入'django.urls'未定义的变量:路径"未定义的变量:"admin"
unresolved import 'django.contrib' unresolved import 'django.urls' Undefined variable: 'path' Undefined variable: 'admin'
推荐答案
您未选择在VS Code中安装Django的虚拟环境(请参见左下角的屏幕快照,其中显示"Python 3.7.4 32-bit";如果您使用的是虚拟环境,则会显示"venv"或类似字词).尝试单击状态栏中的解释器,然后选择您的环境.
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.
这篇关于Visual Studio代码未解析的导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!