In my both Mac (OS X Mavericks) and Ubuntu machine, I have installed sympy that is a python library for symbolic mathematics. Part of sympy is the pretty print functionality that uses unicode characters to prettify symbolic expressions in the command-line environments with unicode support. For example, in my Ubuntu machine and in its gnome-terminal running the following code

from sympy import *
x = Symbol("x")
pprint(Integral(sqrt(1/x), x)) 

renders to

enter image description here

However, the same command in OS X with iTerm2 (that should support unicode) results in

enter image description here

I'm using sympy 0.7.5 that I have made from source with the latest build of iTerm2 (Build Is there anything that I miss here? The lead developer of sympy is one of the StackExchange network. It would be great to know his opinion on this one.

  • At this moment running your example through live.sympy.org throws a lot of unicode errors - maybe there is a general issue with the most recent build?
    – Asmus
    Commented Jun 19, 2014 at 16:23
  • @Asmus what do you mean Unicode errors? If it doesn't render correctly, that is an issue with your browser or the font that it is using.
    – asmeurer
    Commented Jun 19, 2014 at 17:11
  • @asmeurer I tried copy&pasting the above three python lines directly into the browser session (Safari) and had the following output: Exception in SymPy Live of type <type 'exceptions.UnicodeEncodeError'> [. . . ] UnicodeEncodeError: 'ascii' codec can't encode character u'\u2320' in position 0: ordinal not in range(128). I can send you the whole error output if you like.
    – Asmus
    Commented Jun 19, 2014 at 21:02
  • @Asmus if you could open an issue for it that would be great. I can't reproduce it myself.
    – asmeurer
    Commented Jun 19, 2014 at 21:28
  • @asmeurer The issue can now be found here
    – Asmus
    Commented Jun 19, 2014 at 21:36

2 Answers 2


I finally found out what the problem is. The problem was not with the terminal emulators themselves as both OSX Terminal and iTerm2 were using UTF-8 by default. It turned out one has to inform python explicitly that the terminal is capable of handling unicode by way of


Credits to this stackoverflow answer.

  • Interesting, I've never heard of this environment variable. I wonder if this is a situation that is handled better by Python 3.
    – asmeurer
    Commented Jun 20, 2014 at 23:31
  • 1
    This didn't work for me. Even tried Python 3 in the hopes that it might just work, but it didn't. Commented Dec 21, 2015 at 20:17

Make sure your terminal in the iTerm preferences -> Profiles -> Terminal supports Unicode (the character encoding should be "Unicode (UTF-8)". SymPy will choose ASCII if the terminal does not report that it supports Unicode.

  • Thank you for reply. I'm afraid that is not the problem. In both iTerm2 and Terminal I have UTF-8 as character encoding and yet it's not working.
    – Pouya
    Commented Jun 19, 2014 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .