使用国内源(brew, pip, npm)


如果网络不行,安装依赖包的速度小于 100k/s 或者丢包严重导致安装很慢,我认为就应该使用国内源了。今天因为国内源的问题弄了很久,我觉得在国内服务器部署,全部应该从国内下载资源。分为两种情况,
存在国内镜像
没什么好说的,搜索各种使用国内镜像的参数或者弄成配置文件,随服务器迁移
 
不存在国内镜像,直接从国外的官网或者github上面下载
找找有没有国内缓存的文件,比如 Phantomjs,使用 npm 下载会报错,我就找到 淘宝npm镜像地址,选择一个版本,如2.1.1,然后使用 wget 下载到服务器,然后解压,添加软链接。
还有一类国内找不到,比如 tesseract,那就先使用 vpn 下载到本地,再上传到国内云(公司云)上面,然后分享成公开链接,使用 curl 下载到服务器上面。
 
pip 使用国内源
在 pip 最后增加参数
  1. 使用清华源   --index https://pypi.tuna.tsinghua.edu.cn/simple
  2. 或者使用豆瓣源 --index https://pypi.douban.com/simple/

如果非要使用国外的网址,并且连接超时的话,可以增大超时时间尝试一下

 

       --default-timeout=100 

关于配置文件路径。我使用 macos,pip 中文档说配置文件应该放在 $HOME/Library/Application Support/pip/pip.conf 里面,但是我不知道这个路径指什么。于是放在 ~/.pip/pip.conf 里面,也能生效。

brew 使用国内源

使用 npm 安装 phantomjs 遇到的问题:

没有 npm remove -g phantomjs 直接安装就会报错
`Failed at the phantomjs@2.1.7 install script 'node install.js'.
3979 error Make sure you have the latest version of node.js and npm installed.`

但是这样还是有问题,因为 npm -g 会错误,又会从官方源下载(墙外)。所以最终变成:

 

wget https://npm.taobao.org/mirrors/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
    mkdir -p /opt/phantomjs && tar -xjvf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /opt/phantomjs/ && \
    ln -s /opt/phantomjs/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs && \
  rm -rf phantomjs-2.1.1-linux-x86_64

  

npm 使用国内源

增加参数 

--registry=https://registry.npm.taobao.org
npm install -g cnpm --registry=https://registry.npm.taobao.org
文档

参考

pip Config file

https://havee.me/mac/2014-05/individual-scheme-for-pip.html

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM