当前位置:   article > 正文

Jupyter修改默认路径问题(SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb5 in position 0)

syntaxerror: (unicode error) 'utf-8' codec can't decode byte 0xb5 in positio

Jupyter修改默认路径问题

1、问题描述

 Exception while loading config file C:\Users\Administrator\.jupyter\jupyter_notebook_config.py
    Traceback (most recent call last):
      File "C:\mysoftware\install\anacoda\lib\site-packages\traitlets\config\application.py", line 562, in _load_config_files
        config = loader.load_config()
      File "C:\mysoftware\install\anacoda\lib\site-packages\traitlets\config\loader.py", line 457, in load_config
        self._read_file_as_dict()
      File "C:\mysoftware\install\anacoda\lib\site-packages\traitlets\config\loader.py", line 489, in _read_file_as_dict
        py3compat.execfile(conf_filename, namespace)
      File "C:\mysoftware\install\anacoda\lib\site-packages\ipython_genutils\py3compat.py", line 198, in execfile
        exec(compiler(f.read(), fname, 'exec'), glob, loc)
      File "C:\Users\Administrator\.jupyter\jupyter_notebook_config.py", line 214
    SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb5 in position 0: invalid start byte

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在这里插入图片描述

jupyter_notebook_config中具体配置如下:
c.NotebookApp.notebook_dir = 'D:nanligong\mianshi\project\python\第二版\',这里存在中文路径,所以报'utf-8' codec can't decode byte 0xb5 in position 0: invalid start byte的错误。将文件名称去掉或改成中文名称即可。

还有另外一个问题。

[C 23:07:30.387 NotebookApp] Bad config encountered during initialization:
[C 23:07:30.387 NotebookApp] No such notebook dir: ''D:\\\nanligong\\mianshi\\project\\python''
The Jupyter HTML Notebook.

This launches a Tornado based HTML Notebook Server that serves up an
HTML5/Javascript Notebook client.

Subcommands
-----------

Subcommands are launched as `jupyter-notebook cmd [args]`. For information on
using subcommand 'cmd', do: `jupyter-notebook cmd -h`.

list
    List currently running notebook servers.
stop
    Stop currently running notebook server for a given port
password
    Set a password for the notebook server.

Options
-------

Arguments that take values are actually convenience aliases to full
Configurables, whose aliases are listed on the help line. For more information
on full configurables, see '--help-all'.

--debug
    set log level to logging.DEBUG (maximize logging output)
--generate-config
    generate default config file
-y
    Answer yes to any questions instead of prompting.
--no-browser
    Don't open the notebook in a browser after startup.
--pylab
    DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
--no-mathjax
    Disable MathJax
    
    MathJax is the javascript library Jupyter uses to render math/LaTeX. It is
    very large, so you may want to disable it if you have a slow internet
    connection, or for offline use of the notebook.
    
    When disabled, equations etc. will appear as their untransformed TeX source.
--allow-root
    Allow the notebook to be run from root user.
--script
    DEPRECATED, IGNORED
--no-script
    DEPRECATED, IGNORED
--log-level=<Enum> (Application.log_level)
    Default: 30
    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')
    Set the log level by value or name.
--config=<Unicode> (JupyterApp.config_file)
    Default: ''
    Full path of a config file.
--ip=<Unicode> (NotebookApp.ip)
    Default: 'localhost'
    The IP address the notebook server will listen on.
--port=<Int> (NotebookApp.port)
    Default: 8888
    The port the notebook server will listen on.
--port-retries=<Int> (NotebookApp.port_retries)
    Default: 50
    The number of additional ports to try if the specified port is not
    available.
--transport=<CaselessStrEnum> (KernelManager.transport)
    Default: 'tcp'
    Choices: ['tcp', 'ipc']
--keyfile=<Unicode> (NotebookApp.keyfile)
    Default: ''
    The full path to a private key file for usage with SSL/TLS.
--certfile=<Unicode> (NotebookApp.certfile)
    Default: ''
    The full path to an SSL/TLS certificate file.
--client-ca=<Unicode> (NotebookApp.client_ca)
    Default: ''
    The full path to a certificate authority certificate for SSL/TLS client
    authentication.
--notebook-dir=<Unicode> (NotebookApp.notebook_dir)
    Default: ''
    The directory to use for notebooks and kernels.
--browser=<Unicode> (NotebookApp.browser)
    Default: ''
    Specify what command to use to invoke a web browser when opening the
    notebook. If not specified, the default browser will be determined by the
    `webbrowser` standard library module, which allows setting of the BROWSER
    environment variable to override it.
--pylab=<Unicode> (NotebookApp.pylab)
    Default: 'disabled'
    DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.

To see all available configurables, use `--help-all`

Examples
--------

    jupyter notebook                       # start the notebook
    jupyter notebook --certfile=mycert.pem # use SSL/TLS certificate
    jupyter notebook password              # enter a password to protect the server

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103

在这里插入图片描述

还是由于路径错误造成的。c.NotebookApp.notebook_dir = 'D:\nanligong\mianshi\project\python',这里注意需要将D:\nanligong改成D:nanligong,其余的一样即D:\nanligong\mianshi\project\python,这里有点奇葩,一般win上都是需要加上\,但是这里加了反而定位不到。暂时记录一下这个问题吧!还有一个问题。

 NotebookApp] Exception while loading config file C:\Users\Administrator\.jupyter\jupyter_notebook_config.py
    Traceback (most recent call last):
      File "C:\mysoftware\install\anacoda\lib\site-packages\traitlets\config\application.py", line 562, in _load_config_files
        config = loader.load_config()
      File "C:\mysoftware\install\anacoda\lib\site-packages\traitlets\config\loader.py", line 457, in load_config
        self._read_file_as_dict()
      File "C:\mysoftware\install\anacoda\lib\site-packages\traitlets\config\loader.py", line 489, in _read_file_as_dict
        py3compat.execfile(conf_filename, namespace)
      File "C:\mysoftware\install\anacoda\lib\site-packages\ipython_genutils\py3compat.py", line 198, in execfile
        exec(compiler(f.read(), fname, 'exec'), glob, loc)
      File "C:\Users\Administrator\.jupyter\jupyter_notebook_config.py", line 214
        c.NotebookApp.notebook_dir = 'D:\nanligong\mianshi\project\python\'
                                                                          ^
    SyntaxError: EOL while scanning string literal

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

在这里插入图片描述

这里已经指的很清楚了。c.NotebookApp.notebook_dir = 'D:\nanligong\mianshi\project\python\'。末尾不能有\。这个路径的细节也太多了,一行配置3个异常,服了。

最终正确的配置应该是c.NotebookApp.notebook_dir = 'D:nanligong\mianshi\project\python',运行启动命令。控制台如下:

在这里插入图片描述

根据控制台输出,我们发现程序已经正常启动。

在这里插入图片描述

工作目录顺利定位到指定目录。

2、总结

  书上的代码直接运行绝大部分是对的,但是总有一些软件的更新使得作者无能为力。之前的API是对的,但是之后就废弃了或修改了是常有的事。所以我们需要跟踪源代码。这只是一个小小的问题,如果没有前辈的无私奉献,很难想象我们自己一天能学到多少内容。感谢各位前辈的辛勤付出,让我们少走了很多的弯路!

点个赞再走呗!欢迎留言哦!

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号