ImportError: PyCapsule_Import could not import module pyexpat

2024/9/20 19:11:00

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 loadTestsFromNameaddr.filename, addr.module)File "/usr/local/lib/python2.7/dist-packages/nose-1.3.6-py2.7.egg/nose/importer.py", line 47, in importFromPathreturn 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 importFromDirmod = 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 appFile "/opt/bitnami/apps/jenkins/jenkins_home/jobs/CFC Melbourne production pipeline/workspace/main.py", line 28, in <module>from Routes.AdminRoutes import admin_routesFile "/opt/bitnami/apps/jenkins/jenkins_home/jobs/CFC Melbourne production pipeline/workspace/Routes/AdminRoutes.py", line 7, in <module>from thirdpartylib import cloudstorageFile "/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 ETFile "/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']
>>> 
Answer

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!!

https://en.xdnf.cn/q/72261.html

Related Q&A

Python - Get max value in a list of dict

I have a dataset with this structure :In[17]: allIndices Out[17]: [{0: 0, 1: 1.4589, 4: 2.4879}, {0: 1.4589, 1: 0, 2: 2.1547}, {1: 2.1547, 2: 0, 3: 4.2114}, {2: 4.2114, 3: 0}, {0: 2.4879, 4: 0}]Id lik…

Rescaling axis in Matplotlib imshow under unique function call

I have written a function module that takes the argument of two variables. To plot, I hadx, y = pylab.ogrid[0.3:0.9:0.1, 0.:3.5:.5] z = np.zeros(shape=(np.shape(x)[0], np.shape(y)[1]))for i in range(le…

f2py array valued functions

Do recent versions of f2py support wrapping array-valued fortran functions? In some ancient documentation this wasnt supported. How about it now?Lets for example save the following function as func.f…

Unique strings in a pandas dataframe

I have following sample DataFrame d consisting of two columns col1 and col2. I would like to find the list of unique names for the whole DataFrame d. d = {col1:[Pat, Joseph, Tony, Hoffman, Miriam, Good…

finding index of multiple items in a list

I have a list myList = ["what is your name", "Hi, how are you","What about you", "How about a coffee", "How are you"]Now I want to search index of all …

Debugging asyncio code in PyCharm causes absolutely crazy unrepeatable errors

In my project that based on asyncio and asyncio tcp connections that debugs with PyCharm debugger I got very and very very absurd errors.If I put breakpoint on code after running, the breakpoint never …

how to generate pie chart using dict_values in Python 3.4?

I wanted the frequency of numbers in a list which I got using Counter library. Also, I got the keys and values using keys = Counter(list).keys() and values = Counter(list).values() respectively, where …

How can I make start_url in scrapy to consume from a message queue?

I am building a scrapy project in which I have multiple spiders( A spider for each domain). Now, the urls to be scraped come dynamically from a user given query. so basically I do not need to do broad…

Pip install results in this error cl.exe failed with exit code 2

Ive read all of the other questions on this error and frustratingly enough, none give a solution that works. If I run pip install sentencepiece in the cmd line, it gives me the following output.src/sen…

how to communicate two separate python processes?

I have two python programs and I want to communicate them. Both of them are system services and none of them is forked by parent process.Is there any way to do this without using sockets? (eg by cra…