首页 > 代码库 > Python的安装部署

Python的安装部署

为了更好的学习,我们在WindowsLinux上都安装Python 2.7Python 3.5

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

为了避免冲突,把Python3.5解压后的python.exe改为python3.exe


(1) CentOS6安装Python2.7

sudo yum -y install python-devel openssl openssl-devel gcc sqlite-devel
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar zxvf Python-2.7.6.tgz
cd Python-2.7.6
./configure --prefix=/usr/local/python2.7 --with-threads --enable-shared
sudo make
sudo make install altinstall
sudo ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/lib
sudo ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/lib
sudo ln -s /usr/local/python2.7/bin/python2.7 /usr/local/bin
sudo /sbin/ldconfig -v
# OK
python2.7 -V


安装PIP.

wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz --no-check-certificate
tar xf distribute-0.6.49.tar.gz
cd distribute-0.6.49
python2.7 setup.py install
sudo /usr/local/python2.7/bin/easy_install pip
#OK
/usr/local/python2.7/bin/pip install xxx

安装完之后,我们执行python命令,输入exit() 命令退出Python程序

[root@localhost ~]# python

Python 2.6.6 (r266:84292, Aug 18 2016,15:13:37)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]on linux2

Type "help","copyright", "credits" or "license" for moreinformation.

>>> exit()

执行which python命令,你会发现默认的python是在/usr/local/bin/python

目录下,实际上我们新安装的python也在这个目录下

[root@localhost ~]# which python

/usr/bin/python

[root@localhost ~]# python

Python 2.6.6 (r266:84292, Aug 18 2016,15:13:37)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]on linux2

Type "help","copyright", "credits" or "license" for moreinformation.

>>> print"Hello,world"

Hello,world

>>> print "python2.7"

python2.7

>>> 1+2+3

6

>>> exit()

开始练习Python脚本

[root@localhost ~]# cd /tmp

[root@localhost tmp]# vim hello.py

#!/usr/bin/env python

# -*- coding: utf-8 -*-

 

name = raw_input(‘please input yourname:‘)

print "Hello,world!","Ilove meinv",name

print"1+2+3+4+5+6+7+8+9+10=",1+2+3+4+5+6+7+8+9+10

print ‘I\‘m learning\"Python\"!‘

print ‘‘‘line1

line2

line3‘‘‘

 

print ‘中文测试正常

 

[root@localhost tmp]# chmod +x hello.py

[root@localhost tmp]# python hello.py

please input your name:tangtang

Hello,world! I love meinv tangtang

1+2+3+4+5+6+7+8+9+10= 55

I‘m learning "Python"!

line1

line2

line3

中文测试正常


(2) CentOS6安装Python3.5

下载Python3.5的源码包并编译

wgethttps://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz

tar xf Python-3.5.0.tgz

cd Python-3.5.0

./configure --prefix=/usr/local--enable-shared

make

make install

ln –s /usr/local/bin/python3 /usr/bin/python3

 

在运行Python之前需要配置库:

echo /usr/local/lib >>/etc/ld.so.conf.d/local.conf

ldconfig

 

运行演示:

python3 --version

Python 3.5.0


Python的安装部署