简体   繁体   中英

importlib.import_module is not a package

update.py:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--data_file")
job_args = parser.parse_known_args()[0]
imported = importlib.import_module(job_args.data_file)

CURIE_BLR.py
testbed = "CURIE_BLR"
sockets = [
    "10.64.127.135:2005:Fugazi",
    "10.64.127.135:2006:Radium",
    "10.64.127.135:2007:Thallium",
    "10.64.127.135:2008:Thorium",
    "10.64.127.135:2009:Uranium",
    "10.64.127.135:2011:Neptune",
    "10.64.127.135:2033:Promethium"
]

python update_topo_status.py --data_file CURIE_BLR.py

ModuleNotFoundError: No module named 'CURIE_BLR.py'; 'CURIE_BLR' is not a package

You have to import like this:

import argparse
import CURIE_BLR

parser = argparse.ArgumentParser()
parser.add_argument("--data_file")
job_args = parser.parse_known_args()[0]
imported = importlib.import_module(job_args.data_file)


testbed = "CURIE_BLR"
sockets = [
    "10.64.127.135:2005:Fugazi",
    "10.64.127.135:2006:Radium",
    "10.64.127.135:2007:Thallium",
    "10.64.127.135:2008:Thorium",
    "10.64.127.135:2009:Uranium",
    "10.64.127.135:2011:Neptune",
    "10.64.127.135:2033:Promethium"
]

Also your file CURIE_BLR.py should be on the same folder/path where your other python packages/modules are present.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM