c++ - Should the order of import statements matter when importing a .so? -
i getting following import error when trying load python module compiled using boost python.
importerror: /path/to/library/libxml2.so.2: symbol gzopen64, version zlib_1.2.3.3 not defined in file libz.so.1 link time reference
strangely don't see error if non standard module imported. i.e if import other module , module, fails import error. not sure what's going wrong or how debug.
edit: show issue:
$ python -c 'import json, libmyboost_py_lib' # not work!!! traceback (most recent call last): file "<string>", line 1, in <module> importerror: path/to/xml_library/libxml2.so: symbol gzopen64, version zlib_1.2.3.3 not defined in file libz.so.1 link time reference $ python -c 'import libmyboost_py_lib, json' # works now!!! $
its not json, few other modules cause same issue when imported before module. eg. urllib2
the order of import
statements matter.
as documented in python language reference:
once name of module known (unless otherwise specified, term “module” refer both packages , modules), searching module or package can begin. first place checked
sys.modules
, cache of modules have been imported previously. if module found there used in step (2) of import.
any module can change:
sys.modules
- cache of modules importedsys.path
- search path modules
and can change import hooks well:
the import hooks can provide ability load modules zip files, kind of archive files, network, etc.
import libmyboost_py_lib
this statement going modify sys.modules
sure, loading dependencies module cache. may modify sys.path
too. common frameworks (e.g. boost
, zope
, django
, requests
...) ship batteries included / copy of modules depend on.
django
shipsjson
requests
shipsurllib3
to see library load can use:
python -v -c 'import libmyboost_py_lib'
Comments
Post a Comment