容器以管理员权限进入:
sudo docker exec -ti -u root 容器ID bash
下载包:
1.wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tar.xz
解包:
2.tar -xvJf Python-3.9.0.tar.xz
进入python文件夹,生成编译脚本
3.执行
./configure prefix=var/jenkins_home/python3
ps:一下是容器内安装python环境时需要。
若是报缺少包则需安装依赖包:
apt-get install build-essential -y
apt-get install libncurses5-dev libncursesw5-dev libreadline6-dev -y
apt-get install libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev -y
apt-get install libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev -y
apt-get install libssl-dev openssl -y
4.编译:make
cd var/jenkins_home/python3
make && make install
5.设置软连接
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip3
6.并将/usr/local/python3/bin加入PATH
6.1、vim /etc/profile
6.2 、按“I”,然后贴上下面内容:配置环境变量
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
保存
7.让上面修改的文件生效
source ~/.bash_profile
8.检查是否生效
python3 -V
pip3 -V