bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

UnicodeEncodeError: 'ascii' codec can't encode character '\u25cf' in position 9: ordinal not in range(128) #31

Open endrebak opened 5 years ago

endrebak commented 5 years ago

When using Bullet I always get this error.


  File "bin/extract_genotypes", line 28, in <module>
    result = cli.launch()
  File "/home/endrebak/anaconda3/lib/python3.6/site-packages/bullet/client.py", line 670, in launch
    self.result.append((ui.prompt, ui.launch()))
  File "/home/endrebak/anaconda3/lib/python3.6/site-packages/bullet/client.py", line 213, in launch
    self.renderBullets()
  File "/home/endrebak/anaconda3/lib/python3.6/site-packages/bullet/client.py", line 157, in renderBullets
    self.printBullet(i)
  File "/home/endrebak/anaconda3/lib/python3.6/site-packages/bullet/client.py", line 165, in printBullet
    utils.cprint("{}".format(self.bullet) + " " * self.margin, self.bullet_color, back_color, end = '')
  File "/home/endrebak/anaconda3/lib/python3.6/site-packages/bullet/utils.py", line 119, in cprint
    forceWrite(on + color + s + colors.RESET, end = end)
  File "/home/endrebak/anaconda3/lib/python3.6/site-packages/bullet/utils.py", line 101, in forceWrite
    sys.stdout.write(s + end)
UnicodeEncodeError: 'ascii' codec can't encode character '\u25cf' in position 9: ordinal not in range(128)
rcfox commented 5 years ago

Does it work if you run it with the environment variable PYTHONIOENCODING=utf8?

endrebak commented 5 years ago

Yes! Thanks. But the reason I'm using bullet is so that noobs do not need to use scary command line options. I do not want people having to rely on setting env variables. Is there a way to fix this in my python code? You can use sys to set the default encoding, but this is a no-no according to google. Perhaps bullet should print a helpful error message that explains why this happens at least?

rcfox commented 5 years ago

Definitely, this isn't a proper solution, just the easiest way of tracking down the issue.

It is strange though because utf8 should be the default for Python 3. Do you have a different file encoding specified for your own code?

I think the issue is that unicode ● character (\u25cf) in the source file. If you've copied that into your own code with a different file encoding, that could problems.

Also, what do you get from import sys; print(sys.getdefaultencoding())?