Reputation: 10939
I'm setting up IPython to automatically load Sympy and configure it's output method on startup. However, whatever I try I can't get sympy to initialize the latex/unicode style output printing.
Steps taken:
ipython3 create profile sympy
# this is where the profile was created
cd ~/.config/ipython/profile_sympy/startup
gedit 00-startup.py
# add some content (below)
sudo chmod a+x 00-startup.py
The startup script:
import sympy
sympy.init_printing(use_unicode=True)
When I start ipython, it doesn't display a "pretty-printed" output:
ipython3
sympy.sqrt(8)
Output:
2*sqrt(2)
Similar output using qtconsole/notebook.
If I run the init_printing command again the pretty print display works for that kernel instance. Additionally I know the startup script is being run properly because I can add print statements and get output (additionally, the packages are imported and available for use).
I am running sympy 0.7.3, ipython3 1.1, matplotlib 1.3.1, numpy 1.7.1, scipy 0.12.0 on a 64-bit Ubuntu 13.10 install.
Incidentally, running the plain python3 terminal with PYTHONSTARTUP set to run the same startup script will properly pretty print Sympy output.
Upvotes: 4
Views: 2585
Reputation: 10939
In response to Jakob's comment, ipython3 1.1.0 is still using the interactive sympy module instead of sympy 0.7.3's init_printing, which theoretically works fine except I get nasty warning output at start. I'm also not too keen on everything in sympy being imported into the global namespace, which the bundled sympy config does (as well as define a few variables).
However, the suggestion did help me find a fix:
Instead of putting my startup code into the 00-startup.py
, I modified the ipython_config.py
file to execute additional lines at startup:
c.InteractiveShellApp.exec_lines = ['''
import sympy
sympy.init_printing(use_latex=True)
''']
I'm unsure if this is a bug in either sympy or ipython, but this option certainly works.
Upvotes: 3