You are not logged in.
I am trying to import libxml2 in python, but I get the following error:
$ python -c "import libxml2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dynamic module does not define init function (PyInit_libxml2)And for python2 (no surprise here):
$ python2 -c "import libxml2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dynamic module does not define init function (initlibxml2)I have tried to reinstall the following packages from the official repositories, but to no avail:
libxml2
python-lxml
python2-lxml I have had this problem for quite some time (at least half a year) and Google is not helping. Does anyone have any ideas on how to fix this? Thanks!
Last edited by digitaldingo (2015-06-12 15:57:49)
Offline
Where exactly are you getting the py3 module? I see a py2 module included with libxml2, but the python{,2}-lxml packages have nothing to do with this.
Offline
Where exactly are you getting the py3 module? I see a py2 module included with libxml2, but the python{,2}-lxml packages have nothing to do with this.
Good question... I don't see anything related to python3.x either. How would I check where those files are? I can't see anything in site-packages nor does locate find anything.
While I guess this may point to the cause of my problem, I actually only need the python2 module (to build some packages). So I am fine with getting rid of the python3 module (wherever it may be).
Also, I mistook the python{,2}-lxml packages for providing the module based on their description. My bad. Thanks for pointing it out!
Offline
You can pass -v to see from where python is loading each module.
Offline
You can pass -v to see from where python is loading each module.
But of course -- thanks! Importing using -vv I get the following for python2:
>>> import libxml2
# trying libxml2.so
# trying libxml2module.so
# trying libxml2.py
# trying libxml2.pyc
# trying /lib/libxml2.so
dlopen("/lib/libxml2.so", 2);
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initlibxml2)For python3 (again with -vv):
>>> import libxml2
# trying /home/ks/libxml2.cpython-34m.so
# trying /home/ks/libxml2.abi3.so
# trying /home/ks/libxml2.so
# trying /home/ks/libxml2.py
# trying /home/ks/libxml2.pyc
# trying /lib/libxml2.cpython-34m.so
# trying /lib/libxml2.abi3.so
# trying /lib/libxml2.so
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1715, in load_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
ImportError: dynamic module does not define init function (PyInit_libxml2)So I'm guessing that both versions of python try to load /lib/libxml2.so, but fail. /lib/libxml2.so is owned by libxml2 (as expected), and removing and reinstalling libxml2 does not fix the ImportError. Any other ideas on how to proceed from here?
Offline
I'm guessing you've got a really strange $PYTHONPATH
Offline
I'm guessing you've got a really strange $PYTHONPATH
And indeed I did! For whatever reason I had prepended /lib to $PYTHONPATH. Removing that fixed the problem. Thanks a lot!
Offline