[英]Can't import modules - ImportError: No module named
I've created a new app called engineapp
. 我创建了一个名为engineapp
的新应用。 Inside this app, there is a folder engine
which is a Scrapy
project. 在此应用程序内,有一个文件夹engine
,这是一个Scrapy
项目。
When I try to import model from storage
app inside top.py
file, it returns: 当我尝试从top.py
文件中的storage
应用程序导入模型时,它返回:
from storage.models import TopItem
ImportError: No module named storage.models
Or the similar problem, when I try to import settings of scrapy project: 或类似的问题,当我尝试导入scrapy项目的设置时:
from engineapp.engine.engine import settings
It returns: 它返回:
from engineapp.engine.engine import settings
ImportError: No module named engineapp.engine.engine
This is when I run scrapy project from command line. 这是当我从命令行运行scrapy项目时。
Both imports created PyCharm
itself. 两种进口都创建了PyCharm
本身。
As you can see, I've added __init__()
everywhere so python would be able to recognize those files. 如您所见,我到处都添加了__init__()
,以便python能够识别那些文件。
Do you know what should I do to be able to import those files? 您知道我应该怎么做才能导入这些文件吗?
PyCharm autocomplete relies on different IDE settings. PyCharm自动完成功能依赖于不同的IDE设置。 You've marked your realstate_scanner
as sources root, so PyCharm can resolve imports for this. 你标记你的realstate_scanner
为源根,所以PyCharm可以解决这个进口。 From docs: 从文档:
These roots contain the actual source files and resources. 这些根目录包含实际的源文件和资源。 PyCharm uses the source roots as the starting point for resolving imports. PyCharm使用源根作为解决导入的起点。
If you can't import some module in python, you should check PATH/PYTHONPATH variables first to make sure python interpreter knows where to find your module. 如果您无法在python中导入某些模块,则应首先检查PATH / PYTHONPATH变量,以确保python解释器知道在哪里可以找到您的模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.