我有一個文件調(diào)用entryPoint.py:from .commonLib.deviceLib import *我有一個名為deviceLib.py:import mathimport sysimport loggingimport requestsimport thisclass DeviceLib(object): def __init__(self, connectionDb): self.__db = connectionDb樹是這樣的:/test entryPoint.py/commonLib __init__.py deviceLib.py當(dāng)我執(zhí)行時,python entryPoint.py我收到錯誤:Attempted relative import in non-package。請幫我。
3 回答

夢里花落0921
TA貢獻(xiàn)1772條經(jīng)驗 獲得超6個贊
要從另一個目錄導(dǎo)入文件,您可以使用以下代碼:
import sys
sys.path.insert(0, 'folder destination')
import file
正如您在此處看到的,我們包含了路徑,因此 python 也會在該路徑中查找文件。
添加回答
舉報
0/150
提交
取消