运行Gensim文本挖掘代码时VS Code Jupyter内核崩溃求助
VS Code运行Gensim文本挖掘代码时Jupyter内核崩溃(错误码3221225477)
问题详情
运行Gensim开展文本挖掘时,VS Code的Jupyter内核突然崩溃,返回错误码3221225477,核心报错信息:
Canceled future for execute_request message before replies were done
已尝试卸载重装pyzmq、traitlets、jupyter-client,问题依旧;网络搜索数小时未找到有效解决方案。
Conda环境配置
backcall 0.2.0 backports.functools-lru-cache 1.6.4 certifi 2022.6.15 colorama 0.4.5 Cython 0.29.28 debugpy 1.6.0 decorator 5.1.1 entrypoints 0.4 gensim 4.2.0 ipykernel 5.5.0 ipython 7.34.0 ipython-genutils 0.2.0 jedi 0.17.2 jupyter-client 6.1.10 jupyter-core 4.11.1 matplotlib-inline 0.1.3 nest-asyncio 1.5.5 numpy 1.21.6 packaging 21.3 parso 0.7.1 pickleshare 0.7.5 pip 22.1.2 prompt-toolkit 3.0.30 psutil 5.9.1 Pygments 2.12.0 pyparsing 3.0.9 python-dateutil 2.8.2 pywin32 304 pyzmq 19.0.2 scipy 1.7.3 setuptools 63.4.2 six 1.16.0 smart-open 6.0.0 tornado 6.2 traitlets 4.3.3 wcwidth 0.2.5 wheel 0.37.1 wincertstore 0.2
Jupyter日志信息
error 10:30:28.238: Disposing session as kernel process died ExitCode: 3221225477, Reason: info 10:30:28.239: kill daemon error 10:30:28.240: Raw kernel process exited code: 3221225477 error 10:30:28.245: Error in waiting for cell to complete [Error: Canceled future for execute_request message before replies were done at t.KernelShellFutureHandler.dispose (c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:2:32353) at c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:2:51405 at Map.forEach (<anonymous>) at y._clearKernelState (c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:2:51390) at y.dispose (c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:2:44872) at c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:2:2320856 at t.swallowExceptions (c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:7:118974) at dispose (c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:2:2320834) at t.RawSession.dispose (c:\Users\xxxx\.vscode\extensions\ms-toolsai.jupyter-2022.7.1002181843\out\extension.node.js:2:2325771) at processTicksAndRejections (node:internal/process/task_queues:96:5)] warn 10:30:28.246: Cell completed with errors { message: 'Canceled future for execute_request message before replies were done' } info 10:30:28.248: Cancel all remaining cells true || Error || undefined info 10:30:28.248: Cancel pending cells info 10:30:28.250: Cell 22 executed with state Error
可尝试的解决方案
1. 升级Jupyter相关依赖版本
当前ipykernel、jupyter-client、pyzmq版本偏旧,存在兼容性风险,尝试升级到稳定兼容版本:
conda update ipykernel jupyter-client pyzmq
或指定版本安装:
conda install ipykernel==6.15.0 jupyter-client==7.4.2 pyzmq==23.2.0
2. 排查内存占用问题
错误码3221225477对应Windows的内存访问违规,文本挖掘任务(如Word2Vec、LDA训练)易占用大量内存,尝试:
- 缩小单次处理的文本数据规模
- 降低模型参数维度(如Word2Vec的
vector_size参数) - 关闭其他占用内存的程序,释放系统资源
3. 创建全新隔离环境
避免现有环境依赖冲突,创建新conda环境仅安装必要组件:
conda create -n gensim_env python=3.8 conda activate gensim_env conda install gensim jupyter ipykernel python -m ipykernel install --user --name gensim_env --display-name "Python (gensim_env)"
之后在VS Code中切换至该新内核运行代码。
4. 重装底层依赖库
若内存访问违规由numpy、scipy等库的二进制文件兼容问题导致,尝试重装:
conda uninstall scipy numpy conda install scipy numpy
5. 调整VS Code扩展设置
关闭Jupyter扩展的「逐行运行」功能,或暂时禁用其他可能冲突的扩展,重启VS Code后测试。
内容的提问来源于stack exchange,提问作者Arthur
相关产品推荐
相关产品推荐

