Syntax Highlighting in Terminal for Python?

10,837

Solution 1

If you just want to highlight sources you dump into the terminal a la cat try excellent pygments. It actually supports a lot of languages. Run with

pygmentize source.py

If instead you were talking about editing files with syntax highlighting inside a mac terminal, this really depends on the editor.

  • for vi or vim you want at least these option in ~/.vimrc

    syntax on
    
  • emacs works right out of the box

  • don't ask me about nano.

Solution 2

You can try ptpython in github, simply

pip install ptpython

and use it with ptpython.

Solution 3

Try ipython. It highlights syntax and much more.
I haven't tried it on Mac but looks like it must work:
https://stackoverflow.com/questions/726449/installing-ipython-with-readline-on-the-mac

Another option is WxPython and pycrust (which works without Terminal.app :( )

Share:
10,837

Related videos on Youtube

studiohack
Author by

studiohack

Updated on September 17, 2022

Comments

  • studiohack
    studiohack over 1 year

    Is there a way to turn on python syntax highlighting for Terminal.app on Mac OS X?

    • Lawrence Velázquez
      Lawrence Velázquez about 14 years
      Do you mean inside the Python read-eval-print interpreter?
  • user1686
    user1686 about 14 years
    include "/usr/share/nano/python.nanorc" - quite good.