Python文件找不到本地包

问题描述 投票:0回答:1

当我运行

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 在运行文件时做了一些事情

我认为这是一个愚蠢的错误

python bash package pycharm init
1个回答
0
投票

改成:

from .backup_mikrotik import backup_mikrotik
from .backup_eltex import backup_eltex
from .backup_cisco import backup_cisco
© www.soinside.com 2019 - 2024. All rights reserved.