0

我在 Linux 上使用 PyCharm 2020.1。我有这样的导入语句:

from model import *

PyCharm 用红色下划线和错误消息“未解析的参考‘模型’”标记单词模型。

文件夹结构:

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 的这种错误行为?

4

1 回答 1

0

在 PyCharm 中,您需要右键单击根文件夹(例如project)并选择:

Mark Directory as -> Sources Root

于 2020-04-16T14:52:00.077 回答