Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode issues/support? #78

Closed
Lindt8 opened this issue Jun 5, 2018 · 2 comments
Closed

Unicode issues/support? #78

Lindt8 opened this issue Jun 5, 2018 · 2 comments

Comments

@Lindt8
Copy link

Lindt8 commented Jun 5, 2018

I am having the same issue as presented in #74 , but I have tried the workaround listed at #77 and came across an interesting error (see Jupyter terminal output below).

I am using unicode characters in my notebook (though, I am not using copied characters, I am using the decimal code in HTML/markdown, like ², or the Python equivalent, \u00B2, where appropriate). Does nbinteract support unicode? (and, if not will it eventually?) Oddly, the unicode character referenced in the error, \u2265 (the greater-than or equal to sign), is not one I used anywhere in my notebook. When looking at my notebook in Notepad++, that character was not located in the 424231st position like the error states either.

I am still very new to all of this, so it's possible I have goofed somewhere too. Thanks!

(Also, does/will nbinteract have matplotlib support? I don't see matplotlib listed anywhere in your documentation, so perhaps my use of it is what is causing this error?)

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS D:\Google Drive\Sync Locally\SHAEDIT> nbinteract -s Lindt8/SHAEDIT/master SHAEDIT.ipynb
?[0;34m[nbinteract] ?[0mConverting notebooks to HTML...
Traceback (most recent call last):
File "c:\users\hunter\anaconda3\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec)
File "c:\users\hunter\anaconda3\lib\runpy.py", line 85, in _run_code exec(code, run_globals)
File "C:\Users\Hunter\Anaconda3\Scripts\nbinteract.exe\__main__.py", line 9, in <module>
File "c:\users\hunter\anaconda3\lib\site-packages\nbinteract\cli.py", line 166, in main run_converter(arguments)
File "c:\users\hunter\anaconda3\lib\site-packages\nbinteract\cli.py", line 203, in run_converter images_folder=arguments['--images']
File "c:\users\hunter\anaconda3\lib\site-packages\nbinteract\cli.py", line 449, in convert outfile.write(final_output)
File "c:\users\hunter\anaconda3\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2265' in position 424231: character maps to <undefined>
PS D:\Google Drive\Sync Locally\SHAEDIT>

SamLau95 added a commit that referenced this issue Aug 14, 2018
Fixes #78

This avoids encoding issues on Windows where the default encoding is
`cp1252` instead of `utf-8`.

See https://docs.python.org/3/library/codecs.html#encodings-and-unicode
for reference.
@SamLau95
Copy link
Owner

@Lindt8 Looks like the package has some problems when writing the converted notebook on Windows. It turns out that the default open() encoding on Windows is cp1252 while the default encoding on Mac/Linux is utf-8 which appears to handle non-ASCII characters more gracefully.

I've opened #84 to fix this issue by explicitly specifying the encoding for all open() calls. (Sorry about the late response!)

Reference: https://docs.python.org/3/library/codecs.html#encodings-and-unicode

If you're still running into conversion bugs, please link your notebook so I can take a closer look.

@SamLau95
Copy link
Owner

Also, nbinteract has matplotlib support. You can include a plot call in a interact function:

import matplotlib.pyplot as plt
from random import random

def plot_stuff(n_points):
    xs = [random() for _ in range(n_points)]
    ys = [random() for _ in range(n_points)]
    plt.plot(xs, ys)

interact(plot_stuff, n_points=(0, 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants