起因
我在根据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_requestresp.raise_for_status()File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_statusraise 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.jsonDuring 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 jsonreturn complexjson.loads(self.text, **kwargs)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/__init__.py", line 514, in loadsreturn _default_decoder.decode(s)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/decoder.py", line 386, in decodeobj, end = self.raw_decode(s)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/decoder.py", line 416, in raw_decodereturn 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_callexit_code = getattr(module, func_name)(args, parser)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/notices/core.py", line 72, in wrapperreturn_value = func(*args, **kwargs)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda_env/cli/main_create.py", line 156, in executeresult[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 installunlink_link_transaction = solver.solve_for_transaction(File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 156, in solve_for_transactionunlink_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_difffinal_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_statessc = self._collect_all_metadata(ssc)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/common/io.py", line 86, in decoratedreturn f(*args, **kwds)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 467, in _collect_all_metadataindex, r = self._prepare(prepared_specs)File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 1061, in _preparereduced_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_indexnew_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_allresult = tuple(concat(executor.map(subdir_query, channel_urls)))File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 609, in result_iteratoryield fs.pop().result()File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 446, in resultreturn self.__get_result()File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_resultraise self._exceptionFile "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/thread.py", line 58, in runresult = 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 queryself.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 _loadraw_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_requestraise 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 jsonraise 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=falseCONDA_DEFAULT_ENV=baseCONDA_EXE=/home/ubuntu/miniconda3/bin/condaCONDA_PREFIX=/home/ubuntu/miniconda3CONDA_PROMPT_MODIFIER=(base)CONDA_PYTHON_EXE=/home/ubuntu/miniconda3/bin/pythonCONDA_ROOT=/home/ubuntu/miniconda3CONDA_SHLVL=1CURL_CA_BUNDLE=<not set>PATH=/home/ubuntu/.vscode-server/cli/servers/Stable-b58957e67ee1e712cebf466b995adf4c5307b2bd/server/bin/remote-cli:/home/ubuntu/miniconda3/bin:/home/ubuntu/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/binREQUESTS_CA_BUNDLE=<not set>SSL_CERT_FILE=/usr/lib/ssl/certs/ca-certificates.crtactive environment : baseactive env location : /home/ubuntu/miniconda3shell level : 1user config file : /home/ubuntu/.condarcpopulated config files : /home/ubuntu/.condarcconda version : 22.9.0conda-build version : not installedpython version : 3.9.17.final.0virtual packages : __cuda=11.7=0__linux=5.13.0=0__glibc=2.31=0__unix=0=0__archspec=1=x86_64base environment : /home/ubuntu/miniconda3 (writable)conda av data dir : /home/ubuntu/miniconda3/etc/condaconda av metadata url : Nonechannel URLs : https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarchhttps://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64https://mirrors.ustc.edu.cn/anaconda/pkgs/main/noarchhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/noarchhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/linux-64https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/noarchhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarchhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarchhttps://repo.anaconda.com/pkgs/main/linux-64https://repo.anaconda.com/pkgs/main/noarchhttps://repo.anaconda.com/pkgs/r/linux-64https://repo.anaconda.com/pkgs/r/noarchhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/linux-64https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/noarchhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarchpackage cache : /home/ubuntu/miniconda3/pkgs/home/ubuntu/.conda/pkgsenvs directories : /home/ubuntu/miniconda3/envs/home/ubuntu/.conda/envsplatform : linux-64user-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.31UID:GID : 1000:1000netrc file : Noneoffline mode : FalseAn 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]: NNo 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 进行保存
【第三步】重新运行代码
执行上面的操作后,我不再遇到报错,模型也可以正常运行。