首页 > 解决方案 > cmd 上的 Jupyter Notebook

问题描述

尝试使用 cmd 运行 Jupyter Notebook 时出现一些 Unicode 解码错误。

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\sushant>jupyter notebook
[I 21:25:51.729 NotebookApp] Serving notebooks from local directory: C:\Users\sushant
[I 21:25:51.729 NotebookApp] The Jupyter Notebook is running at:
[I 21:25:51.729 NotebookApp] http://localhost:8888/?token=c11161e89ff4d677e940f98f2613308ea70ad4772b86d3ec
[I 21:25:51.729 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Traceback (most recent call last):
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\sushant\AppData\Local\Programs\Python\Python37\Scripts\jupyter-notebook.EXE\__main__.py", line 9, in <module>
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\jupyter_core\application.py", line 266, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\notebook\notebookapp.py", line 1781, in start
    self.write_browser_open_file()
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\notebook\notebookapp.py", line 1700, in write_browser_open_file
    self._write_browser_open_file(open_url, f)
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\notebook\notebookapp.py", line 1708, in _write_browser_open_file
    template = jinja2_env.get_template('browser-open.html')
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\jinja2\environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\jinja2\environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\jinja2\loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "c:\users\sushant\appdata\local\programs\python\python37\lib\site-packages\jinja2\loaders.py", line 175, in get_source
    contents = f.read().decode(self.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9f in position 569274: invalid start byte

标签: python-3.xcmdjupyter-notebook

解决方案


是的。当 pandas 无法读取数据时会发生该错误。我所做的是在文本编辑器中打开数据集,转换为“utf-8”并保存。当您阅读数据集时,请使用:

data = pd.read_csv(<file_name>,encoding='utf-8')

那应该可以解决您的问题。


推荐阅读