当前位置:   article > 正文

【Trick】conda安装python依赖时出现429 Client Error_anaconda安装pandas库失败429

anaconda安装pandas库失败429

起因

我在根据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

完整报错如下:

  1. (base) ubuntu@xiawanke:~/GLC$ conda env create -f environment.yml
  2. Collecting package metadata (repodata.json): failed
  3. # >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
  4. Traceback (most recent call last):
  5. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 531, in fetch_repodata_remote_request
  6. resp.raise_for_status()
  7. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/requests/models.py", line 1021, in raise_for_status
  8. raise HTTPError(http_error_msg, response=self)
  9. requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64/repodata.json
  10. During handling of the above exception, another exception occurred:
  11. Traceback (most recent call last):
  12. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/requests/models.py", line 971, in json
  13. return complexjson.loads(self.text, **kwargs)
  14. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/__init__.py", line 514, in loads
  15. return _default_decoder.decode(s)
  16. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/decoder.py", line 386, in decode
  17. obj, end = self.raw_decode(s)
  18. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/simplejson/decoder.py", line 416, in raw_decode
  19. return self.scan_once(s, idx=_w(s, idx).end())
  20. simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  21. During handling of the above exception, another exception occurred:
  22. Traceback (most recent call last):
  23. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1129, in __call__
  24. return func(*args, **kwargs)
  25. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda_env/cli/main.py", line 80, in do_call
  26. exit_code = getattr(module, func_name)(args, parser)
  27. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/notices/core.py", line 72, in wrapper
  28. return_value = func(*args, **kwargs)
  29. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda_env/cli/main_create.py", line 156, in execute
  30. result[installer_type] = installer.install(prefix, pkg_specs, args, env)
  31. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda_env/installers/conda.py", line 50, in install
  32. unlink_link_transaction = solver.solve_for_transaction(
  33. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 156, in solve_for_transaction
  34. unlink_precs, link_precs = self.solve_for_diff(update_modifier, deps_modifier,
  35. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 199, in solve_for_diff
  36. final_precs = self.solve_final_state(update_modifier, deps_modifier, prune, ignore_pinned,
  37. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 304, in solve_final_state
  38. ssc = self._collect_all_metadata(ssc)
  39. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/common/io.py", line 86, in decorated
  40. return f(*args, **kwds)
  41. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 467, in _collect_all_metadata
  42. index, r = self._prepare(prepared_specs)
  43. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/solve.py", line 1061, in _prepare
  44. reduced_index = get_reduced_index(self.prefix, self.channels,
  45. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/index.py", line 301, in get_reduced_index
  46. new_records = SubdirData.query_all(spec, channels=channels, subdirs=subdirs,
  47. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 137, in query_all
  48. result = tuple(concat(executor.map(subdir_query, channel_urls)))
  49. File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 609, in result_iterator
  50. yield fs.pop().result()
  51. File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 446, in result
  52. return self.__get_result()
  53. File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
  54. raise self._exception
  55. File "/home/ubuntu/miniconda3/lib/python3.9/concurrent/futures/thread.py", line 58, in run
  56. result = self.fn(*self.args, **self.kwargs)
  57. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 129, in <lambda>
  58. subdir_query = lambda url: tuple(SubdirData(Channel(url), repodata_fn=repodata_fn).query(
  59. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 142, in query
  60. self.load()
  61. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 207, in load
  62. _internal_state = self._load()
  63. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 277, in _load
  64. raw_repodata_str = fetch_repodata_remote_request(
  65. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/core/subdir_data.py", line 661, in fetch_repodata_remote_request
  66. raise CondaHTTPError(help_message,
  67. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/conda/exceptions.py", line 552, in __init__
  68. body = response.json()
  69. File "/home/ubuntu/miniconda3/lib/python3.9/site-packages/requests/models.py", line 975, in json
  70. raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
  71. requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  72. `$ /home/ubuntu/miniconda3/bin/conda-env create -f environment.yml`
  73. environment variables:
  74. CIO_TEST=<not set>
  75. CONDA_AUTO_UPDATE_CONDA=false
  76. CONDA_DEFAULT_ENV=base
  77. CONDA_EXE=/home/ubuntu/miniconda3/bin/conda
  78. CONDA_PREFIX=/home/ubuntu/miniconda3
  79. CONDA_PROMPT_MODIFIER=(base)
  80. CONDA_PYTHON_EXE=/home/ubuntu/miniconda3/bin/python
  81. CONDA_ROOT=/home/ubuntu/miniconda3
  82. CONDA_SHLVL=1
  83. CURL_CA_BUNDLE=<not set>
  84. PATH=/home/ubuntu/.vscode-server/cli/servers/Stable-b58957e67ee1e712cebf466
  85. b995adf4c5307b2bd/server/bin/remote-cli:/home/ubuntu/miniconda3/bin:/h
  86. ome/ubuntu/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbi
  87. n:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
  88. REQUESTS_CA_BUNDLE=<not set>
  89. SSL_CERT_FILE=/usr/lib/ssl/certs/ca-certificates.crt
  90. active environment : base
  91. active env location : /home/ubuntu/miniconda3
  92. shell level : 1
  93. user config file : /home/ubuntu/.condarc
  94. populated config files : /home/ubuntu/.condarc
  95. conda version : 22.9.0
  96. conda-build version : not installed
  97. python version : 3.9.17.final.0
  98. virtual packages : __cuda=11.7=0
  99. __linux=5.13.0=0
  100. __glibc=2.31=0
  101. __unix=0=0
  102. __archspec=1=x86_64
  103. base environment : /home/ubuntu/miniconda3 (writable)
  104. conda av data dir : /home/ubuntu/miniconda3/etc/conda
  105. conda av metadata url : None
  106. channel URLs : https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/linux-64
  107. https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/noarch
  108. https://mirrors.ustc.edu.cn/anaconda/pkgs/main/linux-64
  109. https://mirrors.ustc.edu.cn/anaconda/pkgs/main/noarch
  110. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64
  111. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/noarch
  112. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/linux-64
  113. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/noarch
  114. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/linux-64
  115. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/noarch
  116. https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64
  117. https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
  118. https://repo.anaconda.com/pkgs/main/linux-64
  119. https://repo.anaconda.com/pkgs/main/noarch
  120. https://repo.anaconda.com/pkgs/r/linux-64
  121. https://repo.anaconda.com/pkgs/r/noarch
  122. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/linux-64
  123. https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/noarch
  124. https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
  125. https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
  126. package cache : /home/ubuntu/miniconda3/pkgs
  127. /home/ubuntu/.conda/pkgs
  128. envs directories : /home/ubuntu/miniconda3/envs
  129. /home/ubuntu/.conda/envs
  130. platform : linux-64
  131. 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
  132. UID:GID : 1000:1000
  133. netrc file : None
  134. offline mode : False
  135. An unexpected error has occurred. Conda has prepared the above report.
  136. If submitted, this report will be used by core maintainers to improve
  137. future releases of conda.
  138. Would you like conda to send this report to the core maintainers? [y/N]: N
  139. No report sent. To permanently opt-out, use
  140. $ conda config --set report_errors false

通过分析可得到,这个错误是因为请求被限制,导致返回 429 Too Many Requests 错误。

解决方法

通过咨询chat-gpt 3.5,获得了以下几个可能可行的方案

  1. 等待一段时间再尝试:有时服务器会在一段时间内暂时限制你的请求。你可以等待一段时间,然后再尝试运行命令。

  2. 更改镜像源:考虑切换到其他可用的镜像源,可能会有不同的限制。你可以尝试使用官方的 Anaconda 镜像源或者其他可用的镜像源。

  3. 调整网络设置:如果你使用的是代理或者 VPN,请尝试关闭它们,或者尝试使用其他网络环境。

  4. 联系服务器管理员:如果你无法解决问题,可能是服务器端设置了严格的限制。你可以尝试联系服务器管理员,询问是否有关于请求限制的额外信息或者解决方案。

此处我们选择更换镜像源,将中科大的mirror更换为清华的

【第一步】打开服务器中的 .condarc文件

理论上,这个文件应该在根目录下,即 /home/ubuntu/

实在不行也可以  ctrl+f  进行搜索

【第二步】修改内容

  1. channels:
  2. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  3. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  4. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
  5. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  6. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  7. - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  8. - defaults
  9. show_channel_urls: true

此处我把ustc相关的channel都给删除了,然后按  ctrl+s  进行保存

【第三步】重新运行代码

执行上面的操作后,我不再遇到报错,模型也可以正常运行。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/953322
推荐阅读
相关标签
  

闽ICP备14008679号