我正在Linux上使用PyCharm 2020.1。我有一个这样的导入语句:
from model import *
和PyCharm用红色下划线和错误消息“ Unresolved reference'model'”标记单词模型。
文件夹结构:
project
├── ...
├── Chapter6
│ └── FoolBox
│ ├── attack.py <-- this is where i want to run the code
│ ├── data.py
│ └── model.py <-- this is the file i want to import in 'attack.py'
├── Chapter7
├── ...
尽管我运行代码,但运行没有任何问题。我该如何解决PyCharm的这种错误行为?
在PyCharm中,您需要右键单击根文件夹(例如project
),然后选择:
Mark Directory as -> Sources Root