最近更新于 2023-06-07 16:18

环境

Ubuntu 22.04(Windows 11 22H2 专业工作站版 WSL2)

操作

安装依赖

sudo apt update
sudo apt install -y libssl-dev libffi-dev libbz2-dev git build-essential libx11-dev sqlite3 libsqlite3-dev zlib1g-dev libtommath-dev pkg-config

编译安装 tcl/tk(Tkinter 的依赖)

cd /tmp
git clone https://github.com/tcltk/tcl.git --depth=1 --branch=core-8-6-13
cd tcl/unix
./configure
sudo make install -j$(nproc)

cd /tmp
git clone https://github.com/tcltk/tk.git --depth=1 --branch=core-8-6-13
cd tk/unix
./configure
sudo make install -j$(nproc)

编译安装 Python 3.11.3

cd /tmp
git clone https://github.com/python/cpython.git --depth=1 --branch=v3.11.3
cd cpython
./configure --enable-optimizations --enable-loadable-sqlite-extensions --with-tcltk-includes='-I/usr/local/include/' --with-tcltk-libs='/usr/local/lib/libtcl8.6.so /usr/local/lib/libtk8.6.so'
sudo make install -j$(nproc)

编译安装的 Python 可执行文件默认是在 /usr/local/bin 下
file

因为系统预装了 Python3.10.6,目前 python3 软链接的就是它

考虑到系统可能存在依赖关系,这个 python3 的软链接还是保留,给新安装的 Python3.11.3 创建软链接为 python,简化使用

sudo ln -s /usr/local/bin/python3.11 /usr/bin/python

然后测试一下 Tkinter

python -m tkinter

file