使用AppImage方式安装平台无关的Python3环境,在任意Linux系统上无需安装额外依赖,解压即用。
解压appimage
app_image_pkg=$(ls python*.AppImage) && echo $app_image_pkg
chmod +x $app_image_pkg
./$app_image_pkg --appimage-extract # to directory squashfs-root
一键安装脚本
- 安装目录
/opt/$USER/Python3
- 环境变量
# Python环境变量
PYTHON_HOME=/opt/$USER/Python3
export PATH="$PYTHON_HOME/usr/bin:$PATH"
export PYTHONPATH="${PYTHONPATH}:."
#!/usr/bin/env bash
# set -x
set -euo pipefail
cd $(dirname ${BASH_SOURCE[0]})
DEPLOY_DIR=/opt/$USER
if [ ! -e $DEPLOY_DIR ]; then
echo "Create deploy directory: $DEPLOY_DIR"
sudo mkdir -p $DEPLOY_DIR
sudo chown $USER:$USER $DEPLOY_DIR
else
echo "Deploy directory: $DEPLOY_DIR"
fi
cd $DEPLOY_DIR/
PYTHON_PKG=python3.7.16-cp37-cp37m-manylinux2014_x86_64.AppImage
PYTHON_PKG_URL="https://github.com/RanHuang/python-appimage/releases/download/x86_64/python3.7.16-cp37-cp37m-manylinux2014_x86_64.AppImage"
if [ ! -f $PYTHON_PKG ]; then
wget $PYTHON_PKG_URL
fi
if [ ! -d $DEPLOY_DIR/Python-3.7.16 ]; then
chmod +x $PYTHON_PKG
./$PYTHON_PKG --appimage-extract &> /dev/null
mv squashfs-root $DEPLOY_DIR/Python-3.7.16
fi
PYTHON_HOME=$DEPLOY_DIR/Python3
ln -sf $DEPLOY_DIR/Python-3.7.16 $PYTHON_HOME
set +e
bashrc_file=$HOME/.bashrc
cat $bashrc_file | grep -A 2 'Python Env'
if [ $? -ne 0 ]; then
echo "Append the following config to $bashrc_file"
echo -e "\033[31m PYTHON_HOME=$PYTHON_HOME \033[0m"
echo -e "\033[31m export PATH=\"\$PYTHON_HOME/usr/bin:\$PATH\" \033[0m"
echo "# Python Env" >> $bashrc_file
echo "PYTHON_HOME=$PYTHON_HOME" >> $bashrc_file
echo "export PATH=\"\$PYTHON_HOME/usr/bin:\$PATH\"" >> $bashrc_file
fi
set -e
参考资料
niess/python-appimage/releases