![](/img/trans.png)
[英]Import Custom Module in Python [Although it works in PyCharm]
[英]Python module import statement runs in PyCharm but not in VSCode
這是我的文件結構
test/
-dir1
-thing.py
-dir2
-__init__.py
-thing2.py
我正在使用 python 3.7 和 windows 10。
在thing.py
中,我試圖從 thing2.py 導入一個名為foo
的thing2.py
並在我運行thing.py
時執行它。 當我按下運行時,我的代碼在 PyCharm 中完美運行。 但是,當我直接從終端或通過 VSCode 中的代碼運行器運行thing.py
時,出現以下錯誤:
from dir2.thing2 import foo
錯誤: ModuleNotFoundError: No module named 'dir2
這個問題與我的 PYTHONPATH 或其他問題有關嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.