任何来源都无法解析导入;找不到模块

问题描述 投票:0回答:1

由于标题中所述的问题,我无法进行迁移。 image

资源管理器中显示的所有文件都存在相同的问题。 我没有注意到这个问题,直到我去进行民意调查迁移并返回错误:

ModuleNotFoundError:没有模块名称“polls.apps.PollsConfigdjango”; polls.apps 不是一个包

我正在做基本的 Django 教程,这是迄今为止我遇到的唯一问题。

 I tried changing polls.apps.PollsConfig in the installed apps section to have django at the end (as it is shown in the console error).

 I tried changing polls\apps.py to 'from mysite.apps' which shows the same error, as well as 'from polls.apps' which shows a circular error.  I did this to see if VSCode would remove the underline showing there was no longer an error.  'from polls.apps' did remove the underline, however when making the migration it showed a circular error in powershell. 

 I'm figuring on this being a simple beginner error and am hoping someone will know what the issue is at a glance.  It wouldn't bother me at all to start this over and do it again but since I clearly made an error and therefor likely didn't understand something it would be very cool to know what that was and possibly gain some insight.

值得一提的是,我使用的是 Windows 11 附带的 powershell 版本,而不是从 VSCode 使用它;我只使用 VSCode 作为浏览器/编写代码。

以下是包含所需信息的图片:

点冻结

pip freeze

民意调查pps.py

pollsappspy

回溯

traceback

摘自settings.py:

INSTALLED_APPS = [
    'polls.apps.PollsConfig'
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
python django powershell import modulenotfounderror
1个回答
0
投票

列表中第一项后面缺少一个逗号。要修复您的错误,请在民意调查应用程序后面添加一个逗号,如下所示:

INSTALLED_APPS = [
    'polls.apps.PollsConfig', # here 
    ... 
]

请注意,INSTALLED_APPS 应该有一个字符串列表,指定 Django 安装中启用的所有应用程序。 Python 中的列表包含用方括号之间的逗号分隔的项目。

请参阅文档

© www.soinside.com 2019 - 2024. All rights reserved.