一、环境说明
Windows10 + VMware + Ubuntu20.04 + Docker20.10.7
源码:python3.10.2
二、源码下载
$ mkdir build-python
$ cd build-python
$ wget https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz
三、构建编译环境
3.1 编写Dockerfile文件
$ vi Dockerfile
FROM ubuntu
RUN apt update && \
apt install gcc -y && \
apt install make -y && \
apt install libffi-dev -y
3.2 构建编译环境镜像
$ docker build . -t build-python
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
build-python latest b3483e995f0e 24 seconds ago 237MB
ubuntu latest d13c942271d6 4 weeks ago 72.8MB
四、编译源码
4.1 启动容器
$ pwd
/home/tree/code/build-python
$ ls
Dockerfile Python-3.10.2.tgz
$ docker run -itd -v /home/tree/code/build-python:/root --name build-python build-python /bin/bash
获取容器id
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee2622dd7c8b build-python "/bin/bash" 5 seconds ago Up 4 seconds build-python
4.2 进入容器
$ docker exec -it ee2622dd7c8b /bin/bash
4.3 编译
root@ee2622dd7c8b:/# cd /root
root@ee2622dd7c8b:~# tar xf Python-3.9.10.tgz
root@ee2622dd7c8b:~# cd Python-3.9.10
root@ee2622dd7c8b:~# ./configure --with-pydebug
root@ee2622dd7c8b:~# make
注意:只编译了核心的模块代码,对于_curses,_ssl等一些外围模块没编译。