我有以下结构(这是scrapy的标准结构):
root/
.git/
scrapers/
scrapers/
__init__.py
pipelines.py
settings.py
scrapy.cfg
.gitignore
在pipelines.py
中,我正在执行以下导入操作:
from scrapers.settings import API_URL, API_KEY
代码运行得很好!然而,PyCharm用消息Cannot find reference 'settings' in 'imported module scrapers'
将此标记为错误。它认为外部scrapers/
目录是模块根目录。它会错误地认为正确的导入是:
from scrappers.scrapers.settings import API_URL, API_KEY
我尝试将内部scrapers/
目录标记为“sources root”,但没有任何帮助。如何将PyCharm配置为假定此代码的根在内部scrapers/
目录中
从技术上讲,内部
scrapers
目录是一个python包,请参见Packages为了让Pycharm能够定位包,您需要将其父级目录-外部的
scrapers
目录-配置为Sources Root
(即找到包和模块的目录)。从Content root types:相关问题 更多 >
编程相关推荐