Ubuntu22.04下Jupyter Notebook打开.ipynb文件报500错误求助
解决Ubuntu22.04中Jupyter Notebook无法打开.ipynb文件的问题
问题详情
- 环境:Ubuntu22.04,Anaconda创建的名为
FWI的Python3.9虚拟环境 - 操作:通过
conda install jupyter notebook完成Jupyter安装后,执行pip install notebook时触发错误:ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: '/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/pickleshare-0.7.5.dist-info/METADATA` - 症状:无法打开
.ipynb文件,尝试pip install --upgrade、pip install --upgrade nbconvert均无效,终端抛出核心错误:AttributeError: partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import) - 完整错误追踪信息:
Uncaught exception GET /notebooks/notebooks/manuscript.ipynb (xxx.x.x.x) HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/notebooks/manuscript.ipynb', version='HTTP/1.1', remote_ip='xxx.x.x.x') Traceback (most recent call last): File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/bs4/dammit.py", line 28, in <module> import cchardet as chardet_module ModuleNotFoundError: No module named 'cchardet' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/bs4/dammit.py", line 33, in <module> import chardet as chardet_module ModuleNotFoundError: No module named 'chardet' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/tornado/web.py", line 1713, in _execute result = await result File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/tornado/gen.py", line 782, in run yielded = self.gen.send(value) File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/notebook/notebook/handlers.py", line 94, in get self.write(self.render_template('notebook.html', File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/notebook/base/handlers.py", line 511, in render_template return template.render(**ns) File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render self.environment.handle_exception() File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/notebook/templates/notebook.html", line 1, in top-level template code {% extends "page.html" %} File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/notebook/templates/page.html", line 166, in top-level template code {% block header %} File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/notebook/templates/notebook.html", line 115, in block 'header' {% for exporter in get_frontend_exporters() %} File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/notebook/notebook/handlers.py", line 23, in get_frontend_exporters from nbconvert.exporters.base import get_export_names, get_exporter File "/home/master/.local/lib/python3.9/site-packages/nbconvert/__init__.py", line 6, in <module> from . import filters, postprocessors, preprocessors, writers File "/home/master/.local/lib/python3.9/site-packages/nbconvert/filters/__init__.py", line 8, in <module> from .markdown import * File "/home/master/.local/lib/python3.9/site-packages/nbconvert/filters/markdown.py", line 13, in <module> from .markdown_mistune import markdown2html_mistune File "/home/master/.local/lib/python3.9/site-packages/nbconvert/filters/markdown_mistune.py", line 16, in <module> import bs4 File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/bs4/__init__.py", line 37, in <module> from .builder import ( File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/bs4/builder/__init__.py", line 9, in <module> from bs4.element import ( File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/bs4/element.py", line 19, in <module> from bs4.formatter import ( File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/bs4/formatter.py", line 1, in <module> from bs4.dammit import EntitySubstitution File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/bs4/dammit.py", line 37, in <module> import charset_normalizer as chardet_module File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/charset_normalizer/__init__.py", line 23, in <module> from charset_normalizer.api import from_fp, from_path, from_bytes, normalize File "/home/master/anaconda3/envs/FWI/lib/python3.9/site-packages/charset_normalizer/api.py", line 10, in <module> from charset_normalizer.md import mess_ratio AttributeError: partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import) [E 17:02:17.804 NotebookApp] { "Host": "localhost:8888", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Referer": "http://localhost:8888/tree/notebooks", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" }
解决方案
1. 修复损坏的pickleshare包
pip安装失败提示pickleshare的METADATA文件缺失,先通过conda重装该包:
conda activate FWI conda uninstall pickleshare -y && conda install pickleshare -y
2. 解决charset_normalizer循环导入问题
该错误是因为包文件损坏或版本冲突,通过conda重装修复:
conda uninstall charset_normalizer -y && conda install charset_normalizer -y
3. 补全bs4依赖的字符检测库
错误中显示bs4找不到cchardet和chardet,安装这两个包:
conda install chardet cchardet -y
4. 统一Jupyter组件的安装源
避免pip和conda混合安装导致的版本不一致,重装Jupyter相关组件:
conda uninstall jupyter notebook nbconvert -y && conda install jupyter notebook nbconvert -y
5. 验证修复效果
启动Jupyter Notebook,尝试打开目标.ipynb文件:
jupyter notebook
内容的提问来源于stack exchange,提问作者Master Zhang
相关产品推荐
相关产品推荐

