设为首页 收藏本站
查看: 795|回复: 0

[经验分享] 在CentOS 5.3源码安装Python 2.7及模块

[复制链接]

尚未签到

发表于 2016-5-13 11:03:29 | 显示全部楼层 |阅读模式
        最近需要在服务器上建立一个Python环境,第一次做,故做些记录.

        服务器采用的系统为CentOS release 5.3 (Final),采用源码安装Python 2.7.3.

  


        1.Python

        软件包版本: Python-2.7.3

        下载地址: http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2

  


        安装过程:

        a.将软件包至于合适的目录解包.

        此处在/usr/local/src中操作.执行命令:


tar -xjf Python-2.7.3.tar.bz2
         b.配置,编译与安装

        安装过程中没有做特别的要求,所以简单执行如下的命令:


./configure
make
make install
         至此,完成Python安装.

  


        2.安装setuptools和easy_install

        a.获取脚本ez_setup.py.此脚本将帮助获取setuptools的最新版本,并自动安装easy_install.

        执行:


curl http://peak.telecommunity.com/dist/ez_setup.py > ez_setup.py
  
        b.运行脚本ez_setup.py.需要注意的是,运行此脚本时要确定一起工作的Python版本,必要时直接指明是哪个版本.

        执行:


python ez_setup.py
        得到类似下面的输出:

Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg

Processing setuptools-0.6c11-py2.7.egg

Copying setuptools-0.6c11-py2.7.egg to /usr/local/lib/python2.7/site-packages

Adding setuptools 0.6c11 to easy-install.pth file

Installing easy_install script to /usr/local/bin

Installing easy_install-2.7 script to /usr/local/bin


Installed /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg

Processing dependencies for setuptools==0.6c11

Finished processing dependencies for setuptools==0.6c11

 
        此时,查看下目录/usr/local/bin,会见到下面两个文件:

         /usr/local/bin/easy_install

         /usr/local/bin/easy_install-2.7

  
        3.安装几个模块

        下面安装几个需要的模块,包括: jianfan, mysql-python.

        安装jianfan,执行:


easy_install jianfan
      得到类似输出:

Searching for jianfan

Reading http://pypi.python.org/simple/jianfan/

Reading http://code.google.com/p/python-jianfan/

Best match: jianfan 0.0.1

Downloading http://python-jianfan.googlecode.com/files/jianfan-0.0.1.tar.gz

Processing jianfan-0.0.1.tar.gz

Running jianfan-0.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-hLd3H5/jianfan-0.0.1/egg-dist-tmp-vtBk1J

zip_safe flag not set; analyzing archive contents...

Adding jianfan 0.0.1 to easy-install.pth file


Installed /usr/local/lib/python2.7/site-packages/jianfan-0.0.1-py2.7.egg

Processing dependencies for jianfan

Finished processing dependencies for jianfan

 
  安装mysql-python,执行:


easy_install mysql-python
         得到类似输出:

Searching for mysql-python

Reading http://pypi.python.org/simple/mysql-python/

Reading http://sourceforge.net/projects/mysql-python/

Reading http://sourceforge.net/projects/mysql-python

Best match: MySQL-python 1.2.4c1

Downloading http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.4c1.zip#md5=a05925412cd824104da064db6a889613

Processing MySQL-python-1.2.4c1.zip

Running MySQL-python-1.2.4c1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/egg-dist-tmp-1vXEb1

Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz

Extracting in /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/temp/tmp_Z0Yyi

Now working in /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/temp/tmp_Z0Yyi/distribute-0.6.28

Building a Distribute egg in /tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1

/tmp/easy_install-StJ2_u/MySQL-python-1.2.4c1/distribute-0.6.28-py2.7.egg

In file included from /usr/include/mysql/my_config.h:16,

                 from _mysql.c:44:

/usr/include/mysql/my_config_i386.h:1053:1: warning: "HAVE_WCSCOLL" redefined

In file included from /usr/local/include/python2.7/Python.h:8,

                 from _mysql.c:29:

/usr/local/include/python2.7/pyconfig.h:890:1: warning: this is the location of the previous definition

zip_safe flag not set; analyzing archive contents...

Adding MySQL-python 1.2.4c1 to easy-install.pth file


Installed /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.4c1-py2.7-linux-i686.egg

Processing dependencies for mysql-python

Finished processing dependencies for mysql-python

 
       在安装mysql-python,可能会遇到系统缺少和MySQL相关的必要包;此时可以使用yum进行安装.

  执行:


yum install mysql-devel
  
        验证看看刚才的两个模块是否已安装成功,进入python,使用import试试.比如在python交互式shell中,执行:

        import MySQLdb

        如果没有报错,则说明安装已成功.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-216464-1-1.html 上篇帖子: CentOS上15分钟内安装LAMP(适用于所有VPS) 下篇帖子: CentOS下独立SVN服务器的安装与配置详细过程
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表