Linux – Pyexpat import error when running the aws cli

Pyexpat import error when running the aws cli… here is a solution to the problem.

Pyexpat import error when running the aws cli

I’m having some issues running the AWS CLI on Ubuntu 14.04
I keep getting the following error

Traceback (most recent call last):
File "/usr/local/bin/aws", line 15, in <module>
import awscli.clidriver
File "/usr/local/lib/python2.7/dist-packages/awscli/", line 16, in <module>
File "/usr/local/lib/python2.7/dist-packages/botocore/", line 27, in <module>
import botocore.credentials
File "/usr/local/lib/python2.7/dist-packages/botocore/", line 23, in    <module>
from botocore.compat import total_seconds
File "/usr/local/lib/python2.7/dist-packages/botocore/", line 118, in <module>
import xml.etree.cElementTree
File "/usr/lib/python2.7/xml/etree/", line 3, in <module>
from _elementtree import *
ImportError: PyCapsule_Import could not import module "pyexpat"

When I do

 ls -l /usr/lib/python2.7/*/pyexpat*

I see

 -rw-r--r-- 1 root root 69200 Mar 23 01:57 /usr/lib/python2.7/lib-dynload/

Any help is greatly appreciated.


Somehow, the problem is that I have to run aws commands using sudo.


I’m having a similar issue parsing xml in Python (2.7). It was eventually identified as the result of LD_LIBRARY_PATH inaccurate definition of environmental variables. Here’s my case: XML parsing library: The MATLAB version ( between and the system version () confuses, and an ImportError appears when loading MATLAB version , after I defined the LD_LIBRARY_PATH precisely, i.e. excluding the MATLAB library path, and all went well.

Related Problems and Solutions