問題描述:
在項目下的文件執行腳本,可以手動執行
在其他文件目錄下,手動執行腳本報錯誤,提示不存在該模塊。
解決方法:
文件頭加上:
import sys
import os
sys.path += [
os.path.dirname(os.getcwd()),
os.getcwd()
]
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
