ImportError: PyCapsule_Import could not import module “pyexpat”

匿名 (未验证) 提交于 2019-12-03 00:53:01

问题:

I am using Jenkins to build a python (Flask) solution to deploy to Google App Engine. As part of the build process I run a few integration tests.

One of them is failing with the following error.

ERROR: Failure: ImportError (PyCapsule_Import could not import module "pyexpat") ---------------------------------------------------------------------- Traceback (most recent call last):   File "/usr/local/lib/python2.7/dist-packages/nose-1.3.6-py2.7.egg/nose/loader.py", line 420, in loadTestsFromName     addr.filename, addr.module)   File "/usr/local/lib/python2.7/dist-packages/nose-1.3.6-py2.7.egg/nose/importer.py", line 47, in importFromPath     return self.importFromDir(dir_path, fqname)   File "/usr/local/lib/python2.7/dist-packages/nose-1.3.6-py2.7.egg/nose/importer.py", line 94, in importFromDir     mod = load_module(part_fqname, fh, filename, desc)   File "/opt/bitnami/apps/jenkins/jenkins_home/jobs/CFC Melbourne production pipeline/workspace/Tests/test_integration.py", line 4, in <module>     from main import app   File "/opt/bitnami/apps/jenkins/jenkins_home/jobs/CFC Melbourne production pipeline/workspace/main.py", line 28, in <module>     from Routes.AdminRoutes import admin_routes   File "/opt/bitnami/apps/jenkins/jenkins_home/jobs/CFC Melbourne production pipeline/workspace/Routes/AdminRoutes.py", line 7, in <module>     from thirdpartylib import cloudstorage   File "/opt/bitnami/apps/jenkins/jenkins_home/jobs/CFC Melbourne production pipeline/workspace/thirdpartylib/cloudstorage/__init__.py", line 22, in <module>     from cloudstorage_api import *   File "/opt/bitnami/apps/jenkins/jenkins_home/jobs/CFC Melbourne production pipeline/workspace/thirdpartylib/cloudstorage/cloudstorage_api.py", line 37, in <module>     import xml.etree.cElementTree as ET   File "/usr/lib/python2.7/xml/etree/cElementTree.py", line 3, in <module>     from _elementtree import * ImportError: PyCapsule_Import could not import module "pyexpat" 

I have logged onto the VM and searched for this module and this is what i get

xxx@jenkins-pre1:~$ sudo find / -name pyexpat* /usr/lib/python2.7/lib-dynload/pyexpat.so /var/lib/docker/aufs/diff/d0cfa9780fa540e496fd60e38f32c58708374a4a62bc8a6462834c7757a31cdf/usr/lib/python2.7/lib-dy nload/pyexpat.x86_64-linux-gnu.so 

I guess its install but the module cannot be imported. Please help.

The module is in the python path.

>>> import sys >>> print sys.path ['', '/usr/local/lib/python2.7/dist-packages/setuptools-15.2-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/no se-1.3.6-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/pip-7.0.3-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/ python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload' , '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7'] >>>  

回答1:

I found a workaround to this issue:

In your jenkins script, just clear LD_LIBRARY_PATH variable at the beginning:

export LD_LIBRARY_PATH=""

This does the trick!!



回答2:

It seems that /usr/lib/python2.7/lib-dynload/ is not in your Python's path. You can check this with the following Python commands:

import sys print sys.path 

If it does not appear, you can set the PYTHONPATH environment variable:

$ export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/lib-dynload/ 

Please make sure to check whether the PYTHONPATH environment variable is empty or not, if it is empty, please copy the values of the sys.path separated by ":" to it.

Hope I helped.



回答3:

Got this error after I install caffe on UBUNTU 16.04 with gcc 5.4

This works for me:

pip uninstall scikit-image  sudo apt-get install python-skimage 

However above didn't work on another machine which also has this problem:

This works:

ldd /usr/lib/python2.7/lib-dynload/pyexpat.x86_64-linux-gnu.so      linux-vdso.so.1 =>  (0x00007fffa4570000)     libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3ff57dc000)     libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3ff5416000)     libexpat.so.1 => /opt/oracle/product/11.2.0/dbhome_1/lib/libexpat.so.1 (0x00007f3ff52e5000)     /lib64/ld-linux-x86-64.so.2 (0x00005645018a1000) #and just rename that libexpat.so.1 cd /opt/oracle/product/11.2.0/dbhome_1/lib sudo mv libexpat.so.1 libexpat.so.1.bak 

Taken from: http://answers.ros.org/question/227788/pycapsule_import-could-not-import-module-pyexpat-when-running-rosdep-update/?answer=229807



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!