创建Conda环境时出现simplejson ImportError问题求助
ImportError: cannot import name 'JSONDecodeError' from 'simplejson' 解决方法
问题详情
在HPC集群执行conda create -n krak_brack创建新Conda环境时,出现如下错误:
/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") # >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<< Traceback (most recent call last): File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/conda/exceptions.py", line 1118, in __call__ return func(*args, **kwargs) File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/conda/cli/main.py", line 69, in main_subshell exit_code = do_call(args, p) File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/conda/cli/conda_argparse.py", line 89, in do_call module = import_module(relative_mod, __name__.rsplit('.', 1)[0]) File "/cluster/home/2530631/mambaforge/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/conda/cli/main_create.py", line 14, in <module> from ..notices import notices File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/conda/notices/__init__.py", line 3, in <module> from .core import notices # noqa: F401 File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/conda/notices/core.py", line 15, in <module> from . import fetch File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/conda/notices/fetch.py", line 8, in <module> import requests File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/requests/__init__.py", line 45, in <module> from .exceptions import RequestsDependencyWarning File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/requests/exceptions.py", line 9, in <module> from .compat import JSONDecodeError as CompatJSONDecodeError File "/cluster/home/2530631/mambaforge/lib/python3.10/site-packages/requests/compat.py", line 40, in <module> from simplejson import JSONDecodeError ImportError: cannot import name 'JSONDecodeError' from 'simplejson' (unknown location)
当前使用的Conda/Mamba相关版本:
# Name Version Build Channel conda 22.11.1 py310hff52083_1 conda-forge conda-package-handling 2.0.2 pyh38be061_0 conda-forge conda-package-streaming 0.7.0 pyhd8ed1ab_1 conda-forge fonts-conda-ecosystem 1 0 conda-forge fonts-conda-forge 1 0 conda-forge libmamba 1.0.0 h9eff5f0_2 conda-forge libmambapy 1.0.0 py310hd5a56e8_2 conda-forge mamba 1.0.0 py310h51d5547_2 conda-forge python 3.10.6 ha86cf86_0_cpython conda-forge python_abi 3.10 3_cp310 conda-forge requests 2.28.2 pyhd8ed1ab_0 conda-forge setuptools 66.1.1 pyhd8ed1ab_0 conda-forge
解决方案
1. 强制重装simplejson包
问题根源是requests依赖的simplejson包出现损坏或版本不兼容,先在base环境中重装指定版本:
conda install -n base simplejson=3.17.6 -c conda-forge --force-reinstall
如果使用mamba:
mamba install -n base simplejson=3.17.6 -c conda-forge --force-reinstall
2. 升级核心依赖包
升级base环境中的conda和requests,确保依赖版本兼容:
conda update -n base conda requests -c conda-forge
或用mamba:
mamba update -n base conda requests -c conda-forge
3. 临时禁用Conda notices功能(应急方案)
错误触发于加载notices模块,可临时绕过该功能创建环境:
CONDA_NOTICES=false conda create -n krak_brack
若需永久禁用(不推荐):
conda config --set show_notices false
4. 重新初始化Conda/Mamba
若上述方法无效,尝试重置conda初始化:
conda init --reverse conda init bash # 根据你的shell类型替换为zsh等
重启shell后再尝试创建环境。
内容的提问来源于stack exchange,提问作者Riksal96
相关产品推荐
相关产品推荐

