ImportError: No module named thrift

运行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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值