我在 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 的这种错误行为?
在 PyCharm 中,您需要右键单击根文件夹(例如project
)并选择:
Mark Directory as -> Sources Root
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句