运行aws cli时出现Pyexpat导入错误

时间:2014-09-19 12:57:18

标签: linux python-2.7 amazon-web-services command-line-interface aws-cli

我在ubuntu 14.04上运行aws cli时遇到一些问题 我一直收到以下错误

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/clidriver.py", line 16, in <module>
File "/usr/local/lib/python2.7/dist-packages/botocore/session.py", line 27, in <module>
import botocore.credentials
File "/usr/local/lib/python2.7/dist-packages/botocore/credentials.py", line 23, in    <module>
from botocore.compat import total_seconds
File "/usr/local/lib/python2.7/dist-packages/botocore/compat.py", line 118, in <module>
import xml.etree.cElementTree
File "/usr/lib/python2.7/xml/etree/cElementTree.py", line 3, in <module>
from _elementtree import *
ImportError: PyCapsule_Import could not import module "pyexpat"

当我这样做时

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

我得到了

 -rw-r--r-- 1 root root 69200 Mar 23 01:57 /usr/lib/python2.7/lib-dynload/pyexpat.x86_64-linux-gnu.so

非常感谢任何帮助。

修改

不知何故问题是我不得不用sudo运行aws命令。

1 个答案:

答案 0 :(得分:4)

当我在Python(2.7)中进行xml解析时,我遇到了类似的问题。最后,我们发现它是由不准确定义的LD_LIBRARY_PATH环境变量引起的。这是我的情况:xml解析库: libexpat.so 与系统版本之间的MATLAB版本( libexpat.so.1.5.0 )混淆( libexpat.so.1.6.0 ),在我精确定义ImportError之后加载MATLAB版本 libexpat.so 时出现LD_LIBRARY_PATH,即排除MATLAB库路径,一切顺利。