Linux下安装Python3.6和第三方库
如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,
比如yum!!!!!
不要动现有的python2环境!
1、安装python3.6
1、安装依赖软件
yum groupinstall'Development Tools' -y
yum-y 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软件包
https://www.python.org/downloads/
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
3、安装python3
本次装在/usr/local/python3(具体安装位置看个人喜好)
mkdir -p /usr/local/python3
4、解压、编译
tar -xf Python-3.6.5.tgz
cd Python-3.6.5
./configure --prefix=/usr/local/python3
make && make install
5、建立软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
6、并将/usr/local/python3/bin加入PATH
-------------------------------------------------
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
--------------------------------------------------
7、退出是配置生效
source ~/.bash_profile
8、检查Python3及pip3是否正常可用
不行的话在创建一下pip3的软链接(我也不清楚这一步有什么用)
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
2、 安装pip以及setuptools
安装setuptools
毕竟丰富的第三方库是python的优势所在,为了更加方便的安装第三方库,使用pip命令,我们需要进行相应的安装。1、安装pip前需要前置安装setuptools
wget--no-check-certificate https://files.pythonhosted.org/packages/72/c2/c09362ab29338413ab687b47dab03bab4a792e2bbb727a1eb5e0a88e3b86/setuptools-39.0.1.zip
2、解压
unzip setuptools-39.0.1.zip3、编译
cd setuptools-39.0.1python3 setup.py build
python3 setup.py install
安装pip
wget --no-check-certificate https://files.pythonhosted.org/packages/e0/69/983a8e47d3dfb51e1463c1e962b2ccd1d74ec4e236e232625e353d830ed2/pip-10.0.0.tar.gz
tar xf pip-10.0.0.tar.gz
cd pip-10.0.0
python3 setup.py build
python3 setup.py install
如果没有意外的话,pip安装完成
3、参考博文