恒源云 (Gpushare)_ 如何安装包 /pip 加速等?技巧大放送 3!
作者:恒源云
- 2022 年 4 月 01 日
本文字数:2687 字
阅读完需:约 9 分钟
文章来源 | 恒源云社区
原文地址 | 【小技巧-安装篇】
1、执行命令或程序报找不到包,如何安装?
参考 常用命令,使用 apt 安装系统软件或 pip 安装 Python 包。
2、如何设置 pip 加速?
如果 Python 的 pip 安装库或者包总是很慢,可以更换为国内地址后进行下载
国内常见的 pip 源下载地址如下:
阿里云: https://mirrors.aliyun.com/pypi/simple/
腾讯云:https://mirrors.cloud.tencent.com/pypi/simple
豆瓣(douban): https://pypi.douban.com/simple/
中国科技大学: https://pypi.mirrors.ustc.edu.cn/simple/
清华大学: https://pypi.tuna.tsinghua.edu.cn/simple/
临时使用
#通过 -i 参数指定所需要使用的pip源地址去安装numpy库
pip install numpy -i https://mirrors.cloud.tencent.com/pypi/simple
复制代码
永久使用
#通过该命令设置永久使用该pip镜像源
pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple
#修改完成后通过pip命令安装所需要的包
pip install numpy
复制代码
3、如何升级 pip 包管理工具?
#升级前查看pip版本
pip -V #如下返回pip版本为21.0.1
pip 21.0.1 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
#升级 pip 到最新的版本
pip install pip -U
#也可以临时使用指定镜像来升级 pip
pip install -i https://mirrors.cloud.tencent.com/pypi/simple --upgrade pip
#升级后查看pip版本
pip -V #如下显示22.0.4
pip 22.0.4 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
复制代码
4、如何更换 Ubuntu apt 源?
如果使用 apt 源下载东西很慢或者报错,则可以先通过 apt-get update -y 命令更新 apt 源对实例产生缓存,然后通过 apt-get install 包名安装所需要的包。
国内常见的 apt 源下载地址如下,下面镜像源中仅限实例中的 Ubuntu 18.04 系统版本使用,可通过 lsb_release -a | grep Release 名称查询系统版本。
阿里云
#复制以下所有命令粘贴到实例后回车替换阿里云apt镜像源
cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
apt-get update -y
复制代码
华为云
#复制以下所有命令粘贴到实例后回车替换华为云apt镜像源
cat > /etc/apt/sources.list << EOF
deb http://repo.huaweicloud.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu/ bionic main restricted universe multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://repo.huaweicloud.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://repo.huaweicloud.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
apt-get update -y
复制代码
清华大学
#复制以下所有命令粘贴到实例后回车替换腾讯云apt镜像源
cat > /etc/apt/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
EOF
apt-get update -y
复制代码
中国科技大学
#复制以下所有命令粘贴到实例后回车替换腾讯云apt镜像源
cat > /etc/apt/sources.list << EOF
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
EOF
apt-get update -y
复制代码
划线
评论
复制
发布于: 刚刚阅读数: 2
恒源云
关注
专注人工智能云GPU服务器训练平台 2020.12.25 加入
还未添加个人简介
评论