美文网首页马哥Linux运维原创作者投稿菜鸟Python 运维
【原创】Python学习笔记01-CentOS6.8安装Pyth

【原创】Python学习笔记01-CentOS6.8安装Pyth

作者: JokerW | 来源:发表于2017-06-09 17:16 被阅读671次

1、CentOS6.8 安装Python依赖包

# yum依赖包卸载。

# 通过它就能将当初安装某个软件所依赖的东西给清理掉

# 使用yum卸载软件的时候加上–remove-leaves参数

shell> yum install yum-plugin-remove-with-leaves

shell> yum groupinstall "Development Tools"

shell> 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、下载Python源码包并编译安装
到下载页面找对应版本的python:https://www.python.org/downloads/ ,复制其下载链接。然后到shell命令行

# 如果没有wget,yum install wget

shell> wget -c -P '/usr/local/src' https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz

shell> cd /usr/local/src

shell> tar -xvf Python-3.6.1.tar.xz

shell> cd Python-3.6.1

shell> ./configure --prefix=/usr/local/python3.6.1 --enable-shared

shell> make -j 4 && make install

这样Python3.6.1版就安装上了。

3、验证安装
shell下输入

shell> python --version

Python 2.6.6

这是CentOS6.8自带的2.6.6版的Python。

再输入python3的命令验证安装

shell> python3 --version

-bash: python3: command not found

shell> /usr/local/python3.6.1/bin/python3 --version

/usr/local/python3.6.1/bin/python3: error while loading shared libraries: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

shell> ls /usr/local/python3.6.1/lib/

libpython3.6m.so libpython3.6m.so.1.0 libpython3.so pkgconfig/ python3.6/

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

shell> ldconfig

shell> /usr/local/python3.6.1/bin/python3 --version

Python 3.6.1

shell> 

4、添加命令到环境变量

shell> echo 'export PATH=$PATH:/usr/local/python3.6.1/bin' > /etc/profile.d/python3.sh

shell> source /etc/profile.d/python3.sh

或者

shell> ln -s /usr/local/python3.6.1/bin/python3.6 /usr/bin/python3

5、删除编译Python时所需要的库

shell> yum groupremove "Development tools" --remove-leaves

# 这个无法执行,因为关联了yum,yum程序是受保护的

shell> 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、如果需要,设置别名方便使用

shell> alias py=python3

卓格
于 西港 办公室
更新 v0.1 2017年5月29日 14:30:35

相关文章

网友评论

    本文标题:【原创】Python学习笔记01-CentOS6.8安装Pyth

    本文链接:https://www.haomeiwen.com/subject/yasfqxtx.html