[英]PyCharm import file in the same directory
我在 Linux 上使用 PyCharm 2020.1。 我有這樣的導入語句:
from model import *
和 PyCharm 用紅色下划線和錯誤消息“未解析的參考'模型'”標記單詞 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
)和 select:
Mark Directory as -> Sources Root
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.