共计 4537 个字符,预计需要花费 12 分钟才能阅读完成。
文章起源 | 恒源云社区
原文地址 |【小技巧 - 装置篇】
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
正文完