发现Debian 8/9自带的Python2.7和Python3.5很多地方不能用了,试着手动编译安装Python 3.6,同时为了试下新装的代码高亮插件WP-GeSHi-Highlight,记录下安装过程!
目录
1. 安装依赖
sudo apt update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev
如果libreadline-dev找不到,就安装libedit-dev
sudo apt install libedit-dev
2. 下载、编译安装Python 3.6
wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
tar xvf Python-3.6.9.tgz
cd Python-3.6.9
./configure --enable-optimizations --enable-shared --with-ensurepip=install
make -j8
sudo make altinstall
其他版本的Python下载地址: https://www.python.org/ftp/python/
3. 检查是否能用
python3.6 --version
Python 3.6.9
如果报错
python3.6: error while loading shared libraries: libpython3.6m.so.1.0:
cannot open shared object file: No such file or directory
是说静态库文件没找到,其实这个静态库文件就在我们下载的源码里面,一般这样做
cp libpython3.6m.so.1.0 /usr/local/lib/python3.6/
cat "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/python3.6" >> ~/.bashrc && source ~/.bashrc
4. 完成!
当然除了编译安装Python 3.6,还有别的选择,比如从test源中安装预编译好的
sudo echo "deb http://ftp.fr.debian.org/debian testing main" >> /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y python3.6
或者直接将系统升级到最新的Debian 10,因为该发行版本直接支持Python 3.7 🙂