# Pip

Pip 安装需要的 Python 包已经是开发过程的刚需,其中,遇到超时和缓慢的问题也是家常便饭。这里总结一下解决这类问题的方法。

Tensorflow 的安装为例,只需要增加镜像的使用即可实现。

有以下命令供选择,具体到其他包可以替换 Tensorflow

pip install tensorflow -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install tensorflow -i http://pypi.douban.com/simple/ --trusted-host douban.com
pip install tensorflow -i https://pypi.mirrors.ustc.edu.cn/simple/

加入 trusted-host 是因为有些网站不被 pip 所信任,所以可能会出现安装包失败的问题,需要手动加入。

# Conda

有时候创建 conda 环境时没有镜像源的话很容易报 HTTPERROR

可以找到 anaconda/bin ,然后用 vim 修改这个文件: vim ~/.condarc ,具体是在 channels 处增加:

- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

并删除:

- default

如果没有 channels 就自己添加,保证这个文件有这样的内容:

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

然后 ESC 输入 :wq! 退出即可。

# Github

想下载 Github 上面的资源的一种常见方法是挂代理。在终端还可以考虑另一种方法:以镜像站代替。

例如,需要使用 wget 获取 github 的某个资源时:

wget https://github.com/Dao-AILab/causal-conv1d/releases/download/v1.0.0/causal_conv1d-1.0.0+cu118torch1.13cxx11abiFALSE-cp39-cp39-linux_x86_64.whl

会提示超时或无法连接、无法下载。

方法十分简单,用镜像站的网址替代 github.com ,目前可用、好用的镜像站如下:

  • bgithub.xyz

使用就是如下:

wget https://bgithub.xyz/Dao-AILab/causal-conv1d/releases/download/v1.0.0/causal_conv1d-1.0.0+cu118torch1.13cxx11abiFALSE-cp39-cp39-linux_x86_64.whl

可见仅仅替换 github.com 即可。当然,有些镜像站的食用方式并不是这样简单的替代对应域名,也有在 github.com 前加域名的。

更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Runhua Deng 微信支付

微信支付

Runhua Deng alipay

alipay

Runhua Deng paypal

paypal