svenkreiss / unicodeit

Converts LaTeX tags to unicode: \mathcal{H} → ℋ. Available on the web or as Automator script for the Mac.
https://www.unicodeit.net
Other
275 stars 35 forks source link

Mac automator error message #29

Open wuziqiqiqi opened 3 years ago

wuziqiqiqi commented 3 years ago

UnicodeEncodeError: 'ascii' codec can't encode character '\u03b1' in position 0: ordinal not in range(128)”

svenkreiss commented 3 years ago

I haven't seen this error before. Are you using Python2? This is for Python 3 only.

peterparity commented 3 years ago

I ran into the same issue. I solved it by setting the PYTHONIOENCODING environment variable in the automator script, so it becomes:

PYTHONIOENCODING=UTF-8 /usr/local/bin/python3 -m unicodeit.cli $1
svenkreiss commented 3 years ago

Thanks! This is very helpful @peterparity . I assumed this was a given on all Macs. Do you know what you normal io-encoding is? It seems it depends on the terminal. Do you mind sharing the output of:

python3 -c "import sys; print(sys.stdout.encoding)"

Mine says utf-8 already.

peterparity commented 3 years ago

I think the problem for me is that I'm actually using a separately installed python 3 (using anaconda). When I run in the terminal I get UTF-8 for both the anaconda python and the system python. However, when I run inside of Mac automator, the system python gives utf-8 but the anaconda python gives US-ASCII. I'm not sure why this is the case, but it explains why I'm seeing this error.

svenkreiss commented 3 years ago

Very helpful. Thanks! I'll try to put some clarification in the readme.