About me:IT新人,如有不足之处望各位即时评论探讨;文章内容如有侵权,请及时联系本人。
Goals:1、安装python3,python命令指向python3
2、安装pip3,pip命令指向python3
测试安装环境:CentOS Linux release 7.3.1611 (Core)
系统自带Python环境:Python2.7
先输入【python】命令查看当前系统自带python版本,后期需用到版本号。
sudo yum groupinstall “Development tools”
sudo yum -y install gcc-c++
sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
mkdir /usr/local/python3 || 创建python3所在文件夹
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz || 官网下载python3.7.2
tar xvJf Python-3.7.2.tar.xz || 解压下载好的包
cd Python-3.7.2 || 进入解压后的安装文件夹
./configure --prefix=/usr/local/python3 || 配置python3安装选项
[ ./configure –prefix=/usr/local/python3 ---with-shared -with-ssl -without-debug ]---->如遇配置问题换用此命令
make || 编译
make install || 安装
mv /usr/bin/python /usr/bin/python.bak || 更改系统python命令
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python || 建立软链接使python命令指向python3
(此时 cd /usr/bin 使用 python pip install ** 可以进行安装python类库
也可以用/usr/bin/python pip install **)但是建议使用如下方法进行简化:
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 || pip3命令指向pip3
ln -s /usr/local/python3/lib/python3.7/site-packages/pip/pip3 /usr/bin/pip || pip命令指向pip3
(x为查看当前centos自带python版本后所对应)
Vim /usr/bin/yum
将 #!/usr/bin/python 改为#!/usr/bin.python2.x
Vim /usr/libexec/urlgrabber-ext-down
将 #!/usr/bin/python 改为#!/usr/bin.python2.x
过程中可能出现pip一直无命令的提示,就删除/usr/bin/pip
rm -rf /usr/bin/pip
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
解压安装包,安装pip
tar xf pip-9.0.1.tar.gz
cd pip-9.0.1
Python setup.py install (此时的python一定要指向python3)
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip || 修改指向