起因
我在根据yml文件安装依赖和创建虚拟环境时,出现报错,主要报错信息为以下两点:
【1】Collecting package metadata (repodata.json): failed
【2】requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64/repodata.json
完整报错如下:
(base) ubuntu@xiawanke:~/GLC$ conda env create -f environment.yml
Collecting package metadata (repodata.json): failed
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 531, in fetch_repodata_remote_request
resp.raise_for_status()
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64/repodata.json
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/__init__.py", line 514, in loads
return _default_decoder.decode(s)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/decoder.py", line 386, in decode
obj, end = self.raw_decode(s)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/decoder.py", line 416, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1129, in __call__
return func(*args, **kwargs)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda_env/cli/main.py", line 80, in do_call
exit_code = getattr(module, func_name)(args, parser)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/notices/core.py", line 72, in wrapper
return_value = func(*args, **kwargs)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda_env/cli/main_create.py", line 156, in execute
result[installer_type] = installer.install(prefix, pkg_specs, args, env)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda_env/installers/conda.py", line 50, in install
unlink_link_transaction = solver.solve_for_transaction(
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 156, in solve_for_transaction
unlink_precs, link_precs = self.solve_for_diff(update_modifier, deps_modifier,
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 199, in solve_for_diff
final_precs = self.solve_final_state(update_modifier, deps_modifier, prune, ignore_pinned,
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 304, in solve_final_state
ssc = self._collect_all_metadata(ssc)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/common/io.py", line 86, in decorated
return f(*args, **kwds)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 467, in _collect_all_metadata
index, r = self._prepare(prepared_specs)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 1061, in _prepare
reduced_index = get_reduced_index(self.prefix, self.channels,
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/index.py", line 301, in get_reduced_index
new_records = SubdirData.query_all(spec, channels=channels, subdirs=subdirs,
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 137, in query_all
result = tuple(concat(executor.map(subdir_query, channel_urls)))
File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 609, in result_iterator
yield fs.pop().result()
File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 446, in result
return self.__get_result()
File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
raise self._exception
File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 129, in <lambda>
subdir_query = lambda url: tuple(SubdirData(Channel(url), repodata_fn=repodata_fn).query(
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 142, in query
self.load()
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 207, in load
_internal_state = self._load()
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 277, in _load
raw_repodata_str = fetch_repodata_remote_request(
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 661, in fetch_repodata_remote_request
raise CondaHTTPError(help_message,
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/exceptions.py", line 552, in __init__
body = response.json()
File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
`$ /home/ubuntu/miniconda3/bin/conda-env create -f environment.yml`
environment variables:
CIO_TEST=<not set>
CONDA_AUTO_UPDATE_CONDA=false
CONDA_DEFAULT_ENV=base
CONDA_EXE=/home/ubuntu/miniconda3/bin/conda
CONDA_PREFIX=/home/ubuntu/miniconda3
CONDA_PROMPT_MODIFIER=(base)
CONDA_PYTHON_EXE=/home/ubuntu/miniconda3/bin/python
CONDA_ROOT=/home/ubuntu/miniconda3
CONDA_SHLVL=1
CURL_CA_BUNDLE=<not set>
PATH=/home/ubuntu/.vscode-server/cli/servers/Stable-b58957e67ee1e712cebf466
b995adf4c5307b2bd/server/bin/remote-cli:/home/ubuntu/miniconda3/bin:/h
ome/ubuntu/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbi
n:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
REQUESTS_CA_BUNDLE=<not set>
SSL_CERT_FILE=/usr/lib/ssl/certs/ca-certificates.crt
active environment : base
active env location : /home/ubuntu/miniconda3
shell level : 1
user config file : /home/ubuntu/.condarc
populated config files : /home/ubuntu/.condarc
conda version : 22.9.0
conda-build version : not installed
python version : 3.9.17.final.0
virtual packages : __cuda=11.7=0
__linux=5.13.0=0
__glibc=2.31=0
__unix=0=0
__archspec=1=x86_64
base environment : /home/ubuntu/miniconda3 (writable)
conda av data dir : /home/ubuntu/miniconda3/etc/conda
conda av metadata url : None
channel URLs : https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64
https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch
https://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64
https://mirrors.ustc.edu.cn/anaconda/pkgs/main/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/noarch
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
package cache : /home/ubuntu/miniconda3/pkgs
/home/ubuntu/.conda/pkgs
envs directories : /home/ubuntu/miniconda3/envs
/home/ubuntu/.conda/envs
platform : linux-64
user-agent : conda/22.9.0 requests/2.31.0 CPython/3.9.17 Linux/5.13.0-41-generic ubuntu/20.04.5 glibc/2.31
UID:GID : 1000:1000
netrc file : None
offline mode : False
An unexpected error has occurred. Conda has prepared the above report.
If submitted, this report will be used by core maintainers to improve
future releases of conda.
Would you like conda to send this report to the core maintainers? [y/N]: N
No report sent. To permanently opt-out, use
$ conda config --set report_errors false
通过分析可得到,这个错误是因为请求被限制,导致返回 429 Too Many Requests 错误。
解决方法
通过咨询chat-gpt 3.5,获得了以下几个可能可行的方案
-
等待一段时间再尝试:有时服务器会在一段时间内暂时限制你的请求。你可以等待一段时间,然后再尝试运行命令。
-
更改镜像源:考虑切换到其他可用的镜像源,可能会有不同的限制。你可以尝试使用官方的 Anaconda 镜像源或者其他可用的镜像源。
-
调整网络设置:如果你使用的是代理或者 VPN,请尝试关闭它们,或者尝试使用其他网络环境。
-
联系服务器管理员:如果你无法解决问题,可能是服务器端设置了严格的限制。你可以尝试联系服务器管理员,询问是否有关于请求限制的额外信息或者解决方案。
此处我们选择更换镜像源,将中科大的mirror更换为清华的。
【第一步】打开服务器中的 .condarc文件
理论上,这个文件应该在根目录下,即 /home/ubuntu/
实在不行也可以 ctrl+f 进行搜索
【第二步】修改内容
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
此处我把ustc相关的channel都给删除了,然后按 ctrl+s 进行保存
【第三步】重新运行代码
执行上面的操作后,我不再遇到报错,模型也可以正常运行。