背景描述:
由于公司设置了内网,要下载什么模块时只能通过代理。在pip下载模块时,我们可以使用pip install xxx --proxy=http://username:password@ip:port
的方式;而用conda下载模块时就没有相应的–proxy选项了,那么该如何设置conda下的代理呢?
解决方法:
首先,我们要找到.condarc文件,这是conda在运行期间的配置文件,值得注意的是,该文件如果之前没有运行过相关conda config命令的话是不存在的,执行如下命令:
conda config --set use_pip True
#从未没有运行过conda config命令先运行该命令,确保创建了.condarc文件
find -name .condarc #找到文件的路径,默认路径是/root/.condarc
vim /root/.condarc #编辑文件
在.condarc文件加上如下几行:
channels:
#如果要添加国内镜像,在-defaults前加入【-国内源,形如 -http://ali.com】
- defaults
show_channel_urls: True
allow_other_channels: True
proxy_servers:
http: http://username:password@ip:port
https: https://username:password@ip:port
#如果代理有账号和密码的话按上述形式写,如果没有,写成http://ip:port和https://ip:port
ssl_verify: false
use_pip: true
现在使用 conda install xxx命令检验吧!