python3.7对imp.load_source的替代方案

报错信息

DeprecationWarning: the imp module is deprecated in favour of importlib; see the module’s documentation for alternative uses
import imp

示例

Error during startup: Could not load list of options from OpenDroneMap. Is OpenDroneMap installed in /home/simple/ODM? Make sure that OpenDroneMap is installed and that --odm_path is set properly: Unexpected token / in JSON at position 16354

python2.7中使用import imp

odm=imp.load_source('context', sys.argv[2] + '/opendm/context.py')

可以通过odm调用context中的方法。

python3.7中使用import importlib.util

spec2 = importlib.util.spec_from_file_location('context', sys.argv[2] + '/opendm/context.py')
odm = importlib.util.module_from_spec(spec2)
spec2.loader.exec_module(odm)

之后也可以通过odm调用context中的方法。

你可能感兴趣的:(python)