Anaconda中启动Spyder时出现IndentationError异常错误
启动Spyder时出现IndentationError的解决办法
报错信息:
Traceback (most recent call last): File "C:\Users\user\anaconda3\Scripts\spyder-script.py", line 10, in sys.exit(main()) File "C:\Users\user\anaconda3\lib\site-packages\spyder\app\start.py", line 128, in main from spyder.config.manager import CONF File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\manager.py", line 22, in from spyder.config.main import CONF_VERSION, DEFAULTS, NAME_MAP File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\main.py", line 19, in from spyder.config.fonts import MEDIUM, SANS_SERIF File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\fonts.py", line 14, in from spyder.config.utils import is_ubuntu File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\utils.py", line 17, in from spyder_kernels.utils import iofuncs File "C:\Users\user\anaconda3\lib\site-packages\spyder_kernels\utils\iofuncs.py", line 34, in from spyder_kernels.py3compat import getcwd, pickle, PY2, to_text_string File "C:\Users\user\anaconda3\lib\site-packages\spyder_kernels\py3compat.py", line 356 c exec(code, globals, locals) ^ IndentationError: expected an indented block
解决步骤:
- 强制重新安装spyder-kernels包:打开Anaconda Prompt,执行
conda install --force-reinstall spyder-kernels,修复损坏的包文件。 - 更新Spyder及依赖:执行
conda update spyder spyder-kernels,升级到最新稳定版本,修复已知语法问题。 - 创建干净Conda环境:若当前环境依赖混乱,可新建环境重新安装:
conda create -n spyder_env python=3.9 spyder conda activate spyder_env spyder - 手动修复缩进:找到报错文件
C:\Users\user\anaconda3\lib\site-packages\spyder_kernels\py3compat.py,定位第356行,确保exec(code, globals, locals)语句前有正确缩进(通常4个空格),保存后重启Spyder。
内容的提问来源于stack exchange,提问作者MathGeeksJay
相关产品推荐
相关产品推荐

