Python的安装部署
为了更好的学习,我们在Windows和Linux上都安装Python 2.7和Python 3.5https://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-develwget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgztar zxvf Python-2.7.6.tgzcd Python-2.7.6./configure --prefix=/usr/local/python2.7 --with-threads --enable-sharedsudo makesudo make install altinstallsudo ln -s /usr/local/python2.7/lib/libpython2.7.so /usr/libsudo ln -s /usr/local/python2.7/lib/libpython2.7.so.1.0 /usr/libsudo ln -s /usr/local/python2.7/bin/python2.7 /usr/local/binsudo /sbin/ldconfig -v# OKpython2.7 -V 安装PIP.
wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz --no-check-certificatetar xf distribute-0.6.49.tar.gzcd distribute-0.6.49python2.7 setup.py installsudo /usr/local/python2.7/bin/easy_install pip#OK/usr/local/python2.7/bin/pip install xxx 安装完之后,我们执行python命令,输入exit() 命令退出Python程序
# python
Python 2.6.6 (r266:84292, Aug 18 2016,15:13:37)
on linux2
Type "help","copyright", "credits" or "license" for moreinformation.
>>> exit()
执行which python命令,你会发现默认的python是在/usr/local/bin/python
目录下,实际上我们新安装的python也在这个目录下
# which python
/usr/bin/python
# python
Python 2.6.6 (r266:84292, Aug 18 2016,15:13:37)
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脚本
# cd /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 '中文测试正常'
# chmod +x hello.py
# 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
页:
[1]