首页 > 解决方案 > 导入“embed_video.fields”无法解析 Pylance 报告缺少导入

问题描述

我正在做这个项目,我正在使用 VS-code 编辑器。我已经使用 pip install 安装了 Django-embed-video,并且在 INSTALLED_APPS 下的设置中安装了 embed_video。这是 embed_video 在我的电脑上安装的目录:

C:\Users\DEL.L\AppData\Local\Programs\Python\Python39\Lib\site-packages.

但是当我尝试导入“embed_video.fields我收到错误消息说” could not be resolved Pylance report Missing Imports“。

from django.db import models
from embed_video.fields import EmbedVideoField
# Create your models here.

class video(models.Model):
    title = models.CharField(max_length=100)
    added = models.DateTimeField(auto_now_add=True)
    url = EmbedVideoField()

    def __str__(self):
        return str(self.title)
    
    class Meta:
        ordering = ['-added']

标签: pythondjango-modelsvisual-studio-codeembed

解决方案


请在VS Code终端使用命令“ pip --version”查看模块安装工具“pip”的来源,模块安装在这里:

在此处输入图像描述

然后使用“ pip show django-embed-video”查看模块已经安装成功:

在此处输入图像描述

另外,请在模块安装完成后尝试重新加载 VS Code。

在此处输入图像描述

参考:VSCode 中的 Python 环境


推荐阅读