运行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源码包进行安装
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
--------------------------------------------------------
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