Linux下安装Python3.6和第三方库 http://www.zzvips.com/article/156778.html
如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,
比如yum!!!!!
不要动现有的python2环境!
一、安装python3.6
1. 安装依赖环境
1
|
# 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
1
2
|
https: / / www.python.org / downloads /
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
|
3.安装python3
我个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
创建目录:
1
|
# mkdir -p /usr/local/python3
|
解压下载好的Python-3.x.x.tgz
包(具体包名因你下载的Python具体版本不不同⽽而不不同,如:我下载的是Python3.6.1.那我这里就是Python-3.6.1.tgz
)
1
|
# tar -zxvf Python-3.6.1.tgz
|
4.进入解压后的目录,编译安装。
1
2
3
4
|
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3
|
输入make命令
# make
输入make install
make install
或者 make && make install
5.建立python3的软链
1
|
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
|
6.并将/usr/local/python3/bin加入PATH,编译修改配置
1
2
3
4
5
6
7
8
9
|
# 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
|
按ESC,输入:wq回车退出。
修改完记得执行行下面的命令,让上一步的修改生效:
1
|
# source ~/.bash_profile
|
检查Python3及pip3是否正常可用:
# python3 -V
返回 Python 3.6.1
# pip3 -V
返回 pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
总结
以上所述是小编给大家介绍的Python2和Python3.6环境解决共存问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:https://blog.csdn.net/Ren_ger/article/details/83895401