

centos7 下面python2 共存python3
source link: https://www.tuicool.com/articles/qI7FRnI
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

第一步、查看python的版本号以及安装路径;
通过以上的查看可以看到,python默认是指向到python2的,所以这里我们不动它,保持现状态即可。
备注:(因为现在还有很多的系统更新都需要使用到pyhton2 例如:Centos7 的yum 安装和更新。django这些框架现在默认又是使用python3)
第二步、安装python3的相关依赖库,
1.安装python3.7可能使用的依赖 yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel wget yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc yum -y install libffi-devel 2.下载python3 cd /tmp/ wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz 3.解压下载好的压缩包 tar -zxvf Python-3.7.4.tgz 4.配置编译 mkdir /usr/local/python3 cd Python-3.7.4/ ./configure --enable-shared --prefix=/usr/local/python3 --enable-optimizations make make install
第四步、安装完成后,进行 软链接 创建
后期使用就是 直接输入 python 运行的还是python2。输入python3运行的就是pyhton3了。
cd /usr/local/python3/bin/ ln -s /usr/local/python3/bin/python3 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 pip3 install --upgrade pip
这一步可能会出现如下报错:
错误提示:
python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory
解决办法:(进入安装目录把文件拷贝过去即可)
cd /tmp/Python-3.7.4/
cp libpython3.7m.so.1.0 /usr/local/lib64
cp libpython3.7m.so.1.0 /usr/lib/
cp libpython3.7m.so.1.0 /usr/lib64/
第五步、完成所有的安装,下一次更新 建立Python虚拟环境
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK