使用公司代理服务器后的 Anaconda#
当在公司代理服务器后使用 Anaconda 存储库时,您可能会遇到 HTTP 和 SSL 错误,如下所示,这是由于您的 IT 部门管理的自定义安全配置文件所致。
CondaHTTPError: HTTP 000 CONNECTION FAILED for url https://repo.anaconda.com/pkgs/main/win-64/current_repodata.jsonElapsed:
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
If your current network has https://anaconda.net.cn blocked, please file
a support request with your network engineering team.
ConnectTimeout(MaxRetryError("HTTPSConnectionPool(host='repo.anaconda.com', port=443):
Max retries exceeded with url: /pkgs/main/win-64/current_repodata.json
(Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object
at 0x000001B79FFE3278>, 'Connection to repo.anaconda.com timed out.
(connect timeout=9.15)'))"))
有三种可能的解决方法。首先更新 .condarc
文件,然后再尝试其他方法。
更新 .condarc 文件#
Anaconda 建议更新您的 .condarc
文件以包含 proxy_servers
键。这是首选方法,因为它只会影响 conda,而不会影响系统环境变量。
阅读更多关于 .condarc 文件和使用代理。
例如
proxy_servers:
http: http://username:password@corp.com:8080
https: https://username:password@corp.com:8080
您可以通过运行 conda info --all
来查看是否设置了代理。
更新环境变量#
您还可以通过更新系统环境变量来解决此错误。这可能会影响整个系统中的所有 CLI 软件。
要在 Windows 上更改环境变量
在“开始”菜单中,搜索“env”。
选择“编辑帐户的环境变量”。
选择“环境变量…”。
按“新建…”。
添加两个变量
http_proxy
和https_proxy
,它们都具有相同的值:http://proxy-XX:XXX
要在 macOS 上更改环境变量
通过在终端中运行
printenv
来检查当前环境变量设置。要检查特定的环境变量,请使用
echo $variable_name
。通过运行
export variable_name=variable_value
临时更改环境变量。您可以通过运行conda info --all
来检查它是否在那里。
要在 macOS 上永久更改环境变量,请查看此指南。
要在 Linux 上更改环境变量
运行
export variable_name=variable_value
。要从 shell 输出环境变量的值,请运行
echo $variable_name
。
阅读更多关于取消设置、列出和持久化环境变量。
使用 .netrc
身份验证#
.netrc
文件是实现设置 *_PROXY
环境变量或仅在 .condarc
文件中为 conda 配置的相同目标的另一种方法。这种方法的风险在于,在此处更改环境变量将影响整个系统设置。
阅读更多关于 .netrc 文件。