jupyter-book: Errors when running on Windows

Lifted from @kirstieJane feedback in #134

  1. jupyter-book build mybookname fails with:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 693: character maps to <undefined>
  1. jupyter-book create mybookname --demo --overwrite fails with:
PermissionError: [WinError 5] Access is denied: '.\\mybookname\\.git\\objects\\01\\57a78648328b87569df49479a9813ce273e495'

My first guess at solutions: we should add in an .decode('utf-8') when reading in the markdown for (1) and update the documentation to add that the --overwrite command might need to be run with root privileges for (2).

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 18 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s a section on the current status for windows users: tldr – you need to set an environment variable PYTHONUTF8=1 in either powershell or cmd.exe, then run jupyter-book: https://github.com/phaustin/jupyter-book/blob/windows/docs/advanced/advanced.md#working-on-windows

@choldgraf sure thing, opened PR #225 with the proposed fix.

I think https://github.com/jupyter/jupyter-book/commit/cbc512df254938c04207df97d63b170f3c2dd07e fixes it for ff.readlines(), but not ff.writelines(lines), though I’m not sure if the latter is only necessary for my build environment.

I just encountered this same bug today.

C:\jupyter> jupyter-book build mybookname

...

Traceback (most recent call last):                                                                                             
  File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\runpy.py", line 193, in _run_module_as_main      
    "__main__", mod_spec)                                                                                                      
  File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\runpy.py", line 85, in _run_code                 
    exec(code, run_globals)                                                                                                    
  File "C:\Users\Garbagio\AppData\Roaming\Python\Python36\Scripts\jupyter-book.exe\__main__.py", line 9, in <module>           
  File "C:\Users\Garbagio\AppData\Roaming\Python\Python36\site-packages\jupyter_book\main.py", line 31, in main                
    commands[args.command]()                                                                                                   
  File "C:\Users\Garbagio\AppData\Roaming\Python\Python36\site-packages\jupyter_book\build.py", line 267, in build_book        
    lines = ff.readlines()                                                                                                     
  File "c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\encodings\cp1252.py", line 23, in decode         
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]                                                          
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 693: character maps to <undefined>

Adding UTF-8 to the ‘encoding’ argument of the open() function in build.py allowed a successful build afterward.

# Clean markdown for Jekyll quirks (e.g. extra escape characters)
        with open(path_new_file, 'r', encoding='utf8') as ff:
            lines = ff.readlines()

I have encountered similar errors:

SO: Windows 7 Professional SP1 Python 3.7.1

C:\Users\jferraz\Documents\SBQ\CGI\pmqc\wiki
(venv) λ jupyter-book build mybookname
c:\users\jferraz\documents\sbq\cgi\pmqc\wiki\venv\lib\site-packages\jupyter_book\build.py:129: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  site_yaml = yaml.load(ff.read())
c:\users\jferraz\documents\sbq\cgi\pmqc\wiki\venv\lib\site-packages\jupyter_book\build.py:137: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  toc = yaml.load(ff.read())
Convert and copy notebook/md files...
  0%|                                                                                            | 0/35 [00:00<?, ?it/s] Traceback (most recent call last):
  File "C:\Users\jferraz\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\jferraz\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\jferraz\Documents\SBQ\CGI\pmqc\wiki\venv\Scripts\jupyter-book.exe\__main__.py", line 9, in <module>
  File "c:\users\jferraz\documents\sbq\cgi\pmqc\wiki\venv\lib\site-packages\jupyter_book\main.py", line 31, in main
    commands[args.command]()
  File "c:\users\jferraz\documents\sbq\cgi\pmqc\wiki\venv\lib\site-packages\jupyter_book\build.py", line 267, in build_book
    lines = ff.readlines()
  File "C:\Users\jferraz\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 693: character maps to <undefined>

why is jupyter-book trying to access the .git folder? 😃