Jenkins容器安装Python

245 阅读1分钟

默认安装的Jenkins容器的系统版本是Debian 11.2

更新apt-get源

首先默认apt-get下载源超级慢,先修改一下下载源:/etc/apt/sources.list

deb http://mirrors.163.com/debian/ stretch main non-free contrib
deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ stretch-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib

更新软件包

apt-get update # 获取最新的软件包
apt-get upgrade # 升级已安装的软件包

安装Python

报错:

The following packages have unmet dependencies: ncurses-base : Breaks: libtinfo5 (< 6.1) but 6.0+20161126-1+deb9u2 is to be installed

apt-get install libtinfo5

安装python2

# 安装python2
apt-get install python
# 查看版本
python -V

安装python3

# 安装python3
apt-get install python3
# 查看版本
python3 -V

安装pip

# 安装pip
apt-get install python-pip
# 查看版本
pip -V

# 安装pip3
apt-get install python3-pip
# 查看版本
pip3 -V

就是这么简单直接,避免离线安装的坑。

修改pip源

在pip install 的时候,可能会因为pip源原因,导致下载失败,尝试多次看看。

如果还解决不了,可以修改一下pip下载源。

临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent

常用的国内pip源有:

pypi 清华大学源:https://pypi.tuna.tsinghua.edu.cn/simple
pypi 豆瓣源 :http://pypi.douban.com/simple/
pypi 腾讯源:http://mirrors.cloud.tencent.com/pypi/simple
pypi 阿里源:https://mirrors.aliyun.com/pypi/

永久修改

linux

创建文件夹及配置文件

mkdir  ~/.pip
vi  ~/.pip/pip.conf

添加内容

 [global]
 index-url = https://pypi.tuna.tsinghua.edu.cn/simple

windows

直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下

 [global]
 index-url = https://pypi.tuna.tsinghua.edu.cn/simple