python程式在指令行執行提示ModuleNotFoundError: No module named ‘XXX’ 解決方法
這是因為找不到檔案路徑:
解決方法如下:
在報錯的子產品中添加:
import sys
import os
curPath = os.path.abspath(os.path.dirname(file))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
這樣就可以解決了;
python程式在指令行執行提示ModuleNotFoundError: No module named ‘XXX’ 解決方法
這是因為找不到檔案路徑:
解決方法如下:
在報錯的子產品中添加:
import sys
import os
curPath = os.path.abspath(os.path.dirname(file))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
這樣就可以解決了;