前言
记录下安装过程,以便日后查看。
- Ubuntu 20.04.2 LTS (使用的Docker ubuntu:latest,可能会与其他环境略有不同。)
- Python 3.9.5 (发布前最新版本,其他版本操作相通。)
以下操作都是基于ROOT权限下操作,如果不是或者权限不足,请在命令前添加 sudo
环境依赖
- 切换阿里云镜像源加速,Ubuntu 20.04,网络较好可以跳过,如需其他源请自行搜索替换。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| cp /etc/apt/sources.list /etc/apt/sources.list.backup
echo "deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse" > /etc/apt/sources.list
apt update && apt upgrade -y
|
- 安装编译Python需要的依赖包,全面安装,为了编译后不出现各种问题,宁错杀一千不放过一个包。
1 2 3 4
| apt install gcc make wget curl build-essential autoconf automake m4 openssl libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev -y apt install libbz2-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev libssl-dev libsqlite3-dev libcurl4-openssl-dev libgmp3-dev libonig-dev libreadline-dev libxslt1-dev libffi-dev -y
|
下载
选择需要的版本下载XZ Compressed source tabball
,下载速度慢可以考虑镜像下载。
Python下载官网 | Python3.9.5
Python下载镜像 | Python3.9.5
1 2
| wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz
|
安装
以Python3.9.5
安装为例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| xz -d Python-3.9.5.tar.xz tar -xvf Python-3.9.5.tar
cd Python-3.9.5
./configure --prefix=/usr/local/python3.9.5 --enable-optimizations
make && make install
ln -s /usr/local/python3.9.5/bin/python3.9 /usr/local/bin/python3.9 ln -s /usr/local/python3.9.5/bin/pip3.9 /usr/local/bin/pip3.9
|
等待编译完成即可,如果没有什么其他的报错,应该就OK的。
使用
使用python3.9 xxx.py
和pip3.9 install xxxx
怎么喜欢怎么来
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| root@de9bc33b1a58:~# pip3.9 -V pip 21.1.1 from /usr/local/python3.9.5/lib/python3.9/site-packages/pip (python 3.9) root@de9bc33b1a58:~# python3.9 -V Python 3.9.5 root@de9bc33b1a58:~# python3.9 Python 3.9.5 (default, Jun 3 2021, 12:04:16) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import requests >>> print(requests.get("http://ip-api.com/json").json()) { "status":"success", "country":"China", "countryCode":"*", "region":"*", "regionName":"*", "city":"*", "zip":"", "lat":*, "lon":*, "timezone":"Asia/Shanghai", "isp":"*", "org":"", "as":"*", "query":"*" } >>>
|
PIP源
1 2 3 4 5 6 7 8 9
| 清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣:https://pypi.doubanio.com/simple/
# pip3.9 install xxxx -i https://pypi.tuna.tsinghua.edu.cn/simple
|
END.