ImportError: No module named thrift

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 17:37   1137   0

运行python脚本时提示如标题

脚本包含:

sys.path.append('/usr/lib/python2.7/site-packages/')
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

查找发现'/usr/lib/python2.7/site-packages/'目录没有thrift模块

应该是python没有安装thrift模块的原因。 你可以看看/opt/python/Python-2.7.3/lib/python2.7/site-packages目录下,有没有这个文件: thrift-0.9.0-py2.7-linux-i686.egg 如果没有的话,需要先安装一下。

安装方法如下:

1.安装easy_install

http://pypi.python.org/pypi/setuptools#downloads上下载easy_install源码包进行安装

1). 下载:wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e

2). tar xzvf setuptools-0.6c11.tar.gz

3). cd setuptools-0.6c11

4). python setup.py install

easy_install安装完成

2.使用easy_install安装python的thrift模块:

easy_install thrift
Searching for thrift
Reading http://pypi.python.org/simple/thrift/
Best match: thrift 0.9.2
Downloading https://pypi.python.org/packages/source/t/thrift/thrift-0.9.2.tar.gz#md5=91f1c224c46a257bb428431943387dfd
Processing thrift-0.9.2.tar.gz
Running thrift-0.9.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-fnonCT/thrift-0.9.2/egg-dist-tmp-zZUMoh
/usr/local/python/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'use_2to3'
warnings.warn(msg)
zip_safe flag not set; analyzing archive contents...
Adding thrift 0.9.2 to easy-install.pth file

Installed /usr/local/python/lib/python2.7/site-packages/thrift-0.9.2-py2.7-linux-x86_64.egg
Processing dependencies for thrift
Finished processing dependencies for thrift

参考:http://zhidao.baidu.com/link?url=EolJ-pOm0w2OYtztqTmRrOxeNrQ6SqnfGgUyoiMQKjhDiBUWhl6srjFnRuut2QTIWbSq2LqUqiQ9YlZBViyA_-hOp9K2tEfTtkem3J5tbX3

--------------------------------------------------------

sys.path.append:

对于模块和自己写的程序不在同一个目录下,可以把模块的路径通过sys.path.append(路径)添加到程序中。

在程序开头加上:

import sys
sys.path.append(’引用模块的地址')

参考:http://www.cnblogs.com/fnng/archive/2013/05/16/3082729.html

-------------------------------------------------------------

参考:

http://blog.csdn.net/rj03hou/article/details/5709276

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP