第一个python脚本:

[root@backup ~]# cat helloworld.py

print("hello world")

[root@backup ~]# python helloworld.py

hello world

 

安装python3ipython整体环境,非常麻烦,不注意会经常报错,安装不成功,折腾了一天才搞定,流程记录如下:

第一步:安装python3.5

16.5 安装Python 的依赖包

yum groupinstall "Development tools"

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

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

wget https://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=/application/python  --enable-shared
make
make install
ln –s /application/python/bin/python3  /usr/bin/python3

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

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

ldconfig

4、运行演示:

python3 --version

Python 3.5.0

5、删除编译Python时所需要的库,当然也可以不删

yum groupremove "Development tools" --remove-leaveas

yum remove zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel --remove-leaves

6、设置别名方便使用,也可以不用设置

alias py=python3

 

第二步:安装ipython3

1、需要安装setup-tools

地址: 

解压 unzip setuptools-36.5.0.zip

cd setuptools-36.5.0

/application/python/bin/python3 setup.py install

2、安装pip

地址:

tar xf pip-9.0.1.tar.gz

cd pip-9.0.1

/application/python/bin/python3 setup.py install

此时会在/application/python/bin下生成一个名为pip pip3 pip3.5的几个文件夹,说明pip模块已经打包进入了python环境。

3、安装python-setuptoolspython-setuptools-devel

通过yum install安装即可

4、安装ipython

地址:

tar xf ipython-6.0.0.tar.gz

cd ipython-6.0.0

/application/python/bin/python3 setup.py install

5、配置软链接或加入系统环境变量

ln -s /application/python/bin/python3  /usr/bin/python3

ln -s /application/python/bin/ipython3  /usr/bin/ipython3

ln -s /application/python/bin/ipython  /usr/bin/ipython