Conda报错解决:ProxyError: Conda cannot proceed due to an error in your proxy configuration.

目录

原因一:源配置有误

原因二:代理配置有误

原因三:路由配置有误


在需要使用代理的服务器下,创建新conda环境时报错:

conda create -n opencompass python=3.8
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.9) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Collecting package metadata (current_repodata.json): failed

ProxyError: Conda cannot proceed due to an error in your proxy configuration.
Check for typos and other configuration errors in any '.netrc' file in your home directory,
any environment variables ending in '_PROXY', and any other system-wide proxy
configuration settings.

原因一:源配置有误

vim ~/.condarc

# 可用conda源配置
channels:
    - conda-forge
    - defaults
proxy_servers:
    http: http://user:password@xxx.xxx.com:8080
    https: http://user:password@xxx.xxx.com:8080
ssl_verify: false
report_errors: false

注意事项:

  • 密码中如果含有特殊字符,必须进行转义,不能直接写在网址中
 字符转义 
 @%40 
 #%23 
 $%24 
 %%25 
 ^%5E 
 &%26 
 +%2B 
  • proxy_servers配置https时也必须使用http://的网址,否则也可能出现同样的报错(也碰到过配置https://网址后可以正常创建conda环境的服务器,原因不明)

  • 有时候安装库时报错也可能是源配置引起
# 源配置
default_channels:
  - main
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2
proxy_servers:
  http: http://user:password@xxx.xxx.com:8080
  https: http://user:password@xxx.xxx.com:8080
ssl_verify: false
channel_priority: flexible
channels:
  - https://mirrors.aliyun.com/anaconda/pkgs/r
  - https://mirrors.aliyun.com/anaconda/pkgs/msys2
  - https://mirrors.aliyun.com/anaconda/pkgs/main
  - https://mirrors.aliyun.com/anaconda/pkgs/free
  - defaults


# 报错
Collecting package metadata (current_repodata.json): | ERROR conda.auxlib.logz:stringify(155): [Errno Expecting value] : 0
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/simplejson/scanner.py", line 37, in _scan_once
    nextchar = string[idx]
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
  File "/usr/lib/python3/dist-packages/simplejson/scanner.py", line 79, in scan_once
    return _scan_once(string, idx)
  File "/usr/lib/python3/dist-packages/simplejson/scanner.py", line 39, in _scan_once
    raise JSONDecodeError(errmsg, string, idx)
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

原因二:代理配置有误

如果出现CondaHTTPError报错,可以查看环境变量中的代理配置:

env | grep http

如果环境变量中的代理为空,可以手动添加代理(用于访问互联网,与conda无关):

# 可用代理配置一
export http_proxy="http://user:password@xxx.xxx.com:8080"
export https_proxy="http://user:password@xxx.xxx.com:8080"

# 可用代理配置二
export http_proxy=http://user:password@xxx.xxx.com:8080
export https_proxy=http://user:password@xxx.xxx.com:8080

注意事项:pip安装时如果出现网络访问错误,需要将环境变量中的代理置空

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', timeout('timed out'))': /artifactory/pypi-central-repo/simple/paramiko/
export http_proxy=""
export https_proxy=""

如果将代理置空后pip安装仍然报错,可能是DNS配置的问题

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPConnection object at 0x7f3729a486a0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /pypi/simple/numpy/

CentOS的DNS配置可参考:

Linux 静态IP地址修改与报错处理-CSDN博客

原因三:路由配置有误

 如果完成源配置后仍然存在ProxyError或No route to host报错,可以检查网络情况:

# 方式一:能否请求web服务器
curl www.baidu.com

# 方式二:能否ping通
ping www.baidu.com

# 方式三:能否正常路由
traceroute -I www.baidu.com -z 0.005 -q 1

如果网络存在问题,可以检查路由配置:

route

如果存在某个路由导致目标IP指向错误的网关,删除该网关路由:

route del -net 172.18.0.0/16

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值