0
点赞
收藏
分享

微信扫一扫

python __import__ 使用问题

sin信仰 2022-03-12 阅读 47
python

        今天在调试某开源项目时遇到一个比较费解的问题,python 代码中通过 __import__() 来动态导入一个模块,模块对应的文件名是:TestSuite_pmd.py,里面的内容大致如下:

import utils
import re
import time
import os

from test_case import TestCase
from time import sleep
from settings import HEADER_SIZE
from pmd_output import PmdOutput

from settings import FOLDERS
from system_info import SystemInfo
import perf_report
from datetime import datetime
from pktgen import PacketGeneratorHelper

class TestPmd(TestCase):
    ...

        __import__() 调用的报错信息是:        

    dts: No module named 'git'

        由于对 python 不太熟,看到这个错误提示还真是懵圈了,一开始以为是路径的问题,但看其他的 __import__() 调用都正常。很不理解,然后花了好多时间看 __import__() 的具体用法。最后才意识到这个文件可能 import 了其他模块,而其他模块又 import 了 git 模块,同时 git 模块不存在,所以报错。经过验证,发现确实是这样。
 

举报

相关推荐

0 条评论