网上很多安装python3的教程和博客,总是遗留小坑。
我总结个无坑版本:
条件: linux , 有root 权限。
1、预先安装好所需要的依赖包,很重要:
-
yum groupinstall 'Development Tools'
-
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
-
yum install openssl-devel
-
yum install libffi-devel -y
2、开始下载并安装python
-
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
# 如果下载安装包太慢,可以在华为镜像里面下载
# https://(无用的间隔符,请删除)repo.huaweicloud.com/python/
-
tar Jxvf Python-3.7.0.tar.xz
-
-
cd Python-3.7.0/
-
-
./configure --prefix=/usr/local/python3
-
-
make && make install
如果没有报错,python3.7安装成功
接下来就要建立软连接
-
ln -s /usr/local/python3/bin/python3.7 /usr/local/bin/python3
-
-
ln -s /usr/local/python3/bin/pip3.7 /usr/local/bin/pip
-
-
pip install --upgrade pip
安装完成。
直接敲python3 就可以使用python3.7了
-
[root@instance-111111 Python-3.7.0]# python3
-
Python 3.7.0 (default, May 30 2019, 10:45:53)
-
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
-
Type "help", "copyright", "credits" or "license" for more information.
-
>>>
pip镜像设置:
在用户根目录下新建.pip目录,在.pip新建pip.conf:
-
cd ~
-
mkdir .pip
-
cd .pip
-
vim pip.conf
-
-
[global]
-
index-url = http://(删掉括号和内容)mirrors.aliyun.com/pypi/simple/
-
[install]
-
trusted-host=mirrors.aliyun.com
阅读(2036) | 评论(0) | 转发(0) |