环境:

CentOS 6.4

前言:CentOS 6.4系统自带的有python2.6.6版本

一、下载文件

python官网:https://www.python.org/downloads/    

版本:python-2.7.3

setuptools官网:https://pypi.python.org/pypi/setuptools#downloads  

版本:setuptools-0.6c11

pip官网:https://pypi.python.org/pypi/pip#downloads

版本:pip-1.5.6.tar.gz

pymongo官网:https://pypi.python.org/pypi/pymongo#downloads

版本:pymongo-2.7.2.tar.gz

xlrd官网:https://pypi.python.org/pypi/xlrd

版本:xlrd-0.9.3.tar.gz

xlwt官网https://pypi.python.org/pypi/xlwt

版本:xlwt-0.7.5.tar.gz

xlutils官网:https://pypi.python.org/pypi/xlutils

版本:xlutils-1.7.1.tar.gz

cx_Oracle官网:https://pypi.python.org/pypi/cx_Oracle/5.1.3

版本:cx_Oracle-5.1.3.tar.gz

下载

二、安装Python2.7.3

1、查看系统自带的python版本

[root@vm4 webapps]# python -V
Python 2.6.6

2、解压安装python

[root@vm4 logs]#cd /usr

[root@vm4 usr]# mkdir -p python

[root@vm4 usr]# cd python/

将下载的文件Python-2.7.3.tgz上传至python文件夹内

[root@vm4 python]#tar -zvxf Python-2.7.3.tgz

[root@vm4 python]# cd Python-2.7.3

[root@vm4 Python-2.7.3]# ./configure --prefix=/usr/local/python2.7.3

[root@vm4 Python-2.7.3]# make

[root@vm4 Python-2.7.3]# make install

3、安装成功后目录

[root@vm4 Python-2.7.3]# ll /usr/local/python2.7.3/

总计 16

drwxr-xr-x 2 root root 4096 03-21 10:12 bin

drwxr-xr-x 3 root root 4096 03-21 10:07 include

drwxr-xr-x 4 root root 4096 03-21 10:07 lib

drwxr-xr-x 3 root root 4096 03-21 10:07 share

4、建立软件链接

[root@vm4 Python-2.7.3]# ln -s /usr/local/Python-2.7.3/bin/python  /usr/bin/python2.7.3

[root@vm4 Python-2.7.3]# python2.7.3

Python 2.7.3 (default, Mar 21 2013, 10:06:48)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2

注意

如果执行操作[root@vm4 Python-2.7.3]#ln -s /usr/python/Python-2.7.3/bin/python /usr/bin/python
修改老版本的ln指向后,可能会影响yum的使用,yum兼容Python2.6版本。

操作到这里,python就安装成功了.

三、安装python-devel

[root@vm4 python]# yum install python-devel
Installed:
python-devel.x86_64 0:2.6.6-52.el6

Dependency Updated:
python.x86_64 0:2.6.6-52.el6 python-

libs.x86_64 0:2.6.6-52.el6

Complete!

注意:由于python-devel问题,建议python使用默认的版本2.6.6。上面只是介绍如何安装python。

四、安装setuptools

注意:安装成功python之后,才能安装setuptools

1、将下载的文件上传setuptools-0.6c11.tar.gz至python文件夹内

2、解压安装setuptools-0.6c11

[root@vm4 python]# tar -zxvf setuptools-0.6c11.tar.gz
[root@vm4 setuptools-0.6c11]# cd setuptools-0.6c11
[root@vm4 setuptools-0.6c11]# Python-2.7.3 setup.py install
返回如下表示安装成功:
Installed /usr/python/Python-2.7.3/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

3、建立软链接

[root@vm4 setuptools-0.6c11]#ln -s /usr/python/Python-2.7.3/bin/easy_install /usr/bin/easy_install-2.7.3

4、测试

[root@vm4 setuptools-0.6c11]#easy_install2.7.3 numpy

五、安装pip

1、将下载的文件上传pip-1.5.6.tar.gz至python文件夹内

2、解压安装pip-1.5.6

[root@vm4 python]#tar -zxvf pip-1.5.6
[root@vm4 python]# cd pip-1.5.6
[root@vm4 pip-1.5.6]# Python-2.7.3 setup.py install
返回如下表示安装成功:
Installed /usr/python/Python-2.7.3/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg
Processing dependencies for pip==1.5.6
Finished processing dependencies for pip==1.5.6

3、建立软链接

[root@vm4 pip-1.5.6]#ln -s /usr/python/Python-2.7.3/bin/pip /usr/bin/pip-2.7.3

4、测试

[root@vm4 pip-1.5.6]#pip-2.7.3  install nose

五、安装pymongo

python操作mongo时,需要安装此插件

第一种方法

[root@vm4 python]# pip-2.7.3  install pymongo

第二种方法

1、下载文件pymongo-2.7.2.tar.gz并上传至python

2、解压安装

[root@vm4 python]#tar -zxvf pymongo-2.7.2.tar.gz
[root@vm4 python]# cd pymongo-2.7.2
[root@vm4 pymongo-2.7.2]# Python-2.7.3 setup.py install

返回如下表示安装成功:
Installed /usr/python/Python-2.7.3/lib/python2.7/site-packages/pymongo-2.7.2-py2.7-linux-

x86_64.egg
Processing dependencies for pymongo==2.7.2
Finished processing dependencies for pymongo==2.7.2

六、安装xlrd、xlwt、xlutils

xlrd:是python从excel读数据的第三方控件;
xlwt:是python从excel写数据的第三方控件;
xlutils:是python使用xlrd、xlwt的工具箱。若安装不成功,可能原因是需要安装setuptools。

第一种方法

[root@vm4 python]# pip-2.7.3  install xlrd

[root@vm4 python]# pip-2.7.3  install xlwt

[root@vm4 python]# pip-2.7.3  install xlutils

第二种方法

1、下载文件xlrd-0.9.3.tar.gz,xlwt-0.7.5.tar.gz,xlutils-1.7.1.tar.gz并上传至python

2、解压安装xlrd

[root@vm4 python]# tar -zxvf xlrd-0.9.3.tar.gz
[root@vm4 python]# cd xlrd-0.9.3
[root@vm4 xlrd-0.9.3]# Python-2.7.3 setup.py install

3、解压安装xlwt

[root@vm4 python]# tar -zxvf xlwt-0.7.5.tar.gz
[root@vm4 python]# cd xlwt-0.7.5
[root@vm4 xlwt-0.7.5]# Python-2.7.3 setup.py install

4、解压安装xlutils

[root@vm4 python]# tar -zxvf xlutils-1.7.1.tar.gz
[root@vm4 python]# cd xlutils-1.7.1
[root@vm4 xlutils-1.7.1]# Python-2.7.3 setup.py install

七、安装cx_Oracle

python操作oracle时, 需要安装此插件。安装完oracle客户端之后才能安装cx_Oracle.

[root@vm4 python]# pip-2.7.3  install cx_Oracle

Downloading/unpacking cx-Oracle
Downloading cx_Oracle-5.1.3.tar.gz (104kB): 104kB downloaded
Running setup.py (path:/tmp/pip_build_root/cx-Oracle/setup.py) egg_info for package cx-Oracle
Installing collected packages: cx-Oracle
Running setup.py install for cx-Oracle
building 'cx_Oracle' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/opt/oracle/instantclient_11_2/sdk/include -I/usr/include/python2.6 -c cx_Oracle.c -o build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -DBUILD_VERSION=5.1.3
gcc -pthread -shared build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -L/opt/oracle/instantclient_11_2/ -L/usr/lib64 -lclntsh -lpython2.6 -o build/lib.linux-x86_64-2.6-11g/cx_Oracle.so
Successfully installed cx-Oracle
Cleaning up...

安装成功后建立软链接

[root@localhost instantclient_11_2]# ln -s libclntsh.so.11.1 libclntsh.so

(以上安装成功后的包在/usr/lib64/python2.6/site-packages)

八、安装过程中遇到的问题

1、在安装了Python2.7.3之后,执行

  1. [root@vm4 Python-2.7.3]#mv /usr/bin/python /usr/bin/python2.6.6
  2. [root@vm4 Python-2.7.3]#ln -s /usr/python/Python-2.7.3/bin/python /usr/bin/python

再使用yum时,报错:It's possible that the above module doesn't match the current version of Python

分析原因:CentOS 6.4系统默认Python版本是2.6.6,需要升级到Python 2.7.3,由于yum包管理是用python写的,仅仅单独升级python会导致yum无法使用.
出现这种情况的主要原因在于新安装的Python没有YUM服务所依赖的Packages.

解决方法:查找yum文件,并编辑此py文件
[root@Centos ~]# which yum
/usr/bin/yum
[root@Centos ~]# vi /usr/bin/yum
 

#!/usr/bin/python
改为:
#!/usr/bin/python2.6.6 

然后保存OK.

另外,还有一种可能也同样会导致无法使用yum,就是/usr/bin下的python、python2、python2.4三个文件一定不能改变。理论上说yum只是基于python语言,跟版本并没有关系,但是升级过程中确实会出现问题

2、在python运行过程中出现如下错误:

python错误:ImportError: No module named setuptools
这句错误提示的表面意思是:没有setuptools的模块,说明python缺少这个模块,那我们只要安装这个

模块即可解决此问题

解决方法:安装setuptools

3、执行python脚本时,报错

[root@vm4 statistics]# Python-2.7.3 generator.py

Traceback (most recent call last):
File "generator.py", line 3, in <module>
import cx_Oracle
ImportError: No module named cx_Oracle

解决方法:安装cx_Oracle

4、[root@localhost site-packages]# pip install cx_Oracle报错:

Downloading/unpacking cx-Oracle
Downloading cx_Oracle-5.1.3.tar.gz (104kB): 104kB downloaded
Running setup.py (path:/tmp/pip_build_root/cx-Oracle/setup.py) egg_info for package cx-Oracle
Installing collected packages: cx-Oracle
Running setup.py install for cx-Oracle
building 'cx_Oracle' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/opt/oracle/instantclient_11_2/sdk/include -I/usr/include/python2.6 -c cx_Oracle.c -o build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -DBUILD_VERSION=5.1.3
gcc -pthread -shared build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -L/opt/oracle/instantclient_11_2/ -L/usr/lib64 -lclntsh -lpython2.6 -o build/lib.linux-x86_64-2.6-11g/cx_Oracle.so
/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/cx-Oracle/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ONXD3d-record/install-record.txt --single-version-externally-managed --compile:
running install

running build

running build_ext

building 'cx_Oracle' extension

creating build

creating build/temp.linux-x86_64-2.6-11g

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/opt/oracle/instantclient_11_2/sdk/include -I/usr/include/python2.6 -c cx_Oracle.c -o build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -DBUILD_VERSION=5.1.3

creating build/lib.linux-x86_64-2.6-11g

gcc -pthread -shared build/temp.linux-x86_64-2.6-11g/cx_Oracle.o -L/opt/oracle/instantclient_11_2/ -L/usr/lib64 -lclntsh -lpython2.6 -o build/lib.linux-x86_64-2.6-11g/cx_Oracle.so

/usr/bin/ld: cannot find -lclntsh

collect2: ld returned 1 exit status

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/cx-Oracle/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ONXD3d-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/cx-Oracle
Storing debug log for failure in /root/.pip/pip.log

解决方法:[root@localhost instantclient_11_2]# ln -s libclntsh.so.11.1 libclntsh.so

5、执行python脚本时,报./startup.sh: Permission denied

解决方法:chmod u+x *.sh

6、[root@localhost statistics]# ./generator.py

Traceback (most recent call last):
File "./generator.py", line 3, in <module>
import cx_Oracle
ImportError: libaio.so.1: cannot open shared object file: No such file or directory
解决方法:[root@localhost statistics]# yum install libaio

九、python和python-dev以及boost.python的关系

很多时候,很多人搞不清楚,python和python-dev以及boost.python的关系。python是执行环境
,如果你要c/c++中调用python,或者python调用c或者c++,则需要python-dev。boost.python仅仅是对
python-dev进行了封装,很多函数,两边都具有同样的功能,也就是说用python-dev中的也可以如run1
函数,用boost.python中的也行如run2,boost.python的接口封装得更为友好而已如异常处理。

Linux搭建python环境的更多相关文章

  1. Linux搭建python环境中cx_Oracle模块安装遇到的问题与解决方法

    安装或使用cx_Oracle时,需要用到Oracel的链接库,如libclntsh.so.11.1,否则会有各种各样的错误信息. 安装Oracle Instant Client就可得到这个链接库,避免 ...

  2. Linux 笔记 #01# 搭建 Python 环境 & vim 代码高亮

    日常收集 vim editor: How do I enable and disable vim syntax highlighting? 搭建 Python 环境 vim editor: How d ...

  3. 4、搭建Python环境

    搭建Python环境 Linux环境 大多Linux发行版均默认安装了Pthon环境.如想下载不同的版本,可到www.python.org下载.软件安装方法参照Linux软件安装. 输入Python可 ...

  4. Python 简明教程 --- 1,搭建Python 环境

    微信公众号:码农充电站pro 个人主页:https://codeshellme.github.io 人生苦短,我用Python. -- 龟叔T恤 Python 是一门解释型语言,所以要想运行Pytho ...

  5. Sublime Text 2下搭建Python环境常见错误

    Sublime Text 2下搭建Python环境时,最容易出的错误就是Python环境配置错误,导致build(Ctrl+B)后没有任何反应. 关于Python编程环境的配置,网上很容易搜索到.先默 ...

  6. window搭建python环境

    在window开发python代码,搭建python环境! 01.下载python-win https://www.python.org/downloads/windows/ http://ipyth ...

  7. 【OS X系统】Xcode中搭建Python环境。

    虽然按照网上教程一步一步来,但还是遇到了几个错误点,现整理出来,主要是自己做个笔记,同时也希望能帮助到其他像我一样第一次在Xcode上搭建Python环境的人.首先感谢原作者:https://zhid ...

  8. 转 windows下安装pycharm并连接Linux的python环境 以及 windows 下notepad ++编辑 linux 的文件

    ######sample 1:windows下安装pycharm并连接Linux的python环境 https://www.cnblogs.com/junxun/p/8287998.html wind ...

  9. source insight搭建python环境

    SI是一个受到广泛欢迎的代码阅读/编辑器,那么能不能用SI来进行python开发呢,经过一晚上的试验,终于实现了这一功能. 1.python的语法高亮 source insight 4.0版本已经默认 ...

随机推荐

  1. bootstrap glyphicon图标无法显示

    如果不注意bootstrap引入css和fonts的规范,则可能会导致bootstrap 在显示glyphicon图标时无法正常显示,显示为方框. 此时可搜索bootstrap.css中的.glyph ...

  2. Android sdk manager不能更新下载缓慢的解决方法

    通常情况下,下载Android SDK需要连接谷歌的服务器进行下载,由于国内水深火热的网络,速度基本为0.好在国内也有一个更新的镜像地址.本文章介绍如何在不FQ的情况下,使用国内镜像地址,更新andr ...

  3. Android5.0新特性——新增的Widget(Widget)

    新增的Widget RecyclerView RecyclerView是ListView的升级版,它具备了更好的性能,且更容易使用.和ListView一样,RecyclerView是用来显示大量数据的 ...

  4. Javascript的一种代码结构方式——插件式

    上几周一直在做公司的webos的前端代码的重构,之中对javascript的代码进行了重构(之前的代码耦合严重.拓展.修改起来比较困难),这里总结一下当中使用的一种代码结构——插件式(听起来怎么像独孤 ...

  5. SAPScript、Smartforms动态打印图像或者背景图片

    在利用 SMARTFORMS 进行打印的时候有时候要求输出的图片可能是随着打印内容的不同而不同了,也就是动态输出图片,SMARTFORMS的提供了相关的支持技术,下面是实现截图 1.创建要显示的图片 ...

  6. 2015年第14本(英文第10本):The A.B.C. Murders (A.B.C谋杀案)

    书名:The ABC Murders 推荐指数:5星 作者:Agatha Christie 单词数:7万 不重复单词数:不详 首万词不重复单词数:不详 蓝思值:740 阅读时间:2015年7月18日 ...

  7. bash shell命令(2)

    在上篇<bash shell命令(1)>中,介绍了几种简单的linux shell命令,今天继续介绍bash shell命令 本文地址:http://www.cnblogs.com/arc ...

  8. 关于bitcode~

    最近在做语音识别- 在真机调试的时候一直报 ld: '/Users/Chenglijuan/Documents/语音识别/lib/iflyMSC.framework/iflyMSC(IFlyRecog ...

  9. jquery错误: Cannot read property ‘msie’ of undefined

    背景 Web application, 引用了jquery 1.10.2和fancybox 1.3.4 现象 访问页面遭遇Cannot read property ‘msie’ of undefine ...

  10. Effective Java 35 Prefer annotations to naming patterns

    Disadvantages of naming patterns Typographical errors may result in silent failures. There is no way ...