当我运行
backup.py
时,我得到ModuleNotFoundError: No module named 'router_move'
backup.py
import socket
from router_move.backup_mikrotik import backup_mikrotik
from router_move.backup_eltex import backup_eltex
from router_move.backup_cisco import backup_cisco
def run_backup(directory: str) -> None:
try:
backup_mikrotik(directory)
backup_eltex(directory)
backup_cisco(directory)
except socket.gaierror:
print('unknown ip')
if __name__ == '__main__':
run_backup('/Users/egorgulido/Desktop')
但是如果我用 PyCharm 运行这个文件,它确实可以正常工作
树
路由器移动/
├──
__init__.py
app.py
backup.py
backup_cisco.py
backup_eltex.py
backup_mikrotik.py
models.py
views.py
我没有任何线索。 可能是,PyCharm 在运行文件时做了一些事情
我认为这是一个愚蠢的错误
改成:
from .backup_mikrotik import backup_mikrotik
from .backup_eltex import backup_eltex
from .backup_cisco import backup_cisco