# Buggy code
def print_exception():
    """Print exceptions with/without traceback."""
    env = getattr(builtins, "__xonsh_env__", os.environ)
    if "XONSH_SHOW_TRACEBACK" not in env:
        sys.stderr.write(
            "xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True\n"
        )
    if env.get("XONSH_SHOW_TRACEBACK", False):
        traceback.print_exc()
    else:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        exception_only = traceback.format_exception_only(exc_type, exc_value)
        sys.stderr.write("".join(exception_only))


# Traceback (ImportError)
Collecting xonsh
Using cached xonsh-0.3.0.tar.gz
Installing collected packages: xonsh
Running setup.py install for xonsh ... error
Complete output from command /Users/AlexCory/.pyenv/versions/3.4.0/bin/python3.4 -u -c "import setuptools, tokenize;__file__='/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-v801xh9z-record/install-record.txt --single-version-externally-managed --compile:
╓██▄
╙██▀██╕
▐██4Φ█▀█▌
²██▄███▀██^██
-███╩▀ " ╒▄█████▀█
║██▀▀W╤▄▀ ▐║█╘ ╝█
▄m▀%Φ▀▀  ╝*"    ,α█████▓▄,▄▀Γ"▀╕
"▀██¼"     ▄═╦█╟║█▀ ╓ `^`   ,▄ ╢╕
,▀╫M█▐j╓╟▀ ╔▓▄█▀  '║ ╔    ╣║▌  ▀▄
▄m▀▀███╬█╝▀  █▀^      "ÜM  j▐╟╫╨▒   ╙▀≡═╤═m▀╗
█æsæ╓  ╕, ,▄Ä   ▐'╕H   LU  ║║╠╫Å^2=⌐         █
▄æ%Å███╠█ª╙▄█▀      $1╙       ║║╟╫╩*T▄           ▌
╙╗%▄,╦██▌█▌█╢M         ╕      M║║║║█═⌐ⁿ"^         ╫
╙╣▀████@█░█    ▌╕╕   `      ▌║▐▐║█D═≈⌐¬ⁿ      s ║⌐
╙╬███▓║█`     ▌╚     ╕   ╕▌║▐▐╣▌⌐*▒▒Dù`       ▐▌
╙╬██╨U█      ╟      $ ▌ ▌▌▐▐▐M█▄═≤⌐%       ╓⌐ ▌
║║█▄▌║             ╟ ▌ ▌M▐▐▐M█▀▒▒▒22,       ▐▌
███╙^▌            ║ ▌ ⌐M▐▐▐M█≤⌐⌐¬──        ▐M
║██ ▌╙   ╓       H║ ▌╒ M║▐▐M█"^^^^^"ⁿ      ║
██╕╙@▓   ╕      ▌║ H'  ║▐▐▐█══=.,,,       █
╙█▓╔╚╚█     ╠   ▌└╒ ▌▐ ╚║║║▀****ⁿ -      ╓▌
╙█▌¼V╚▌   ▌  ╕ ▌ ║╒ ║ ▌▒╠█▀≤≤≤≤≤⌐       █
╙█▌╔█╚▌     ┘ M ▌║ ╫ UUM██J^^"        ▐▌
╙██╙█╙▌  ╕$j  ▐⌐▌ ▌║╝╟█Å%%%≈═        █
╙╣█╣█^▌ ╠║▐  ║ ▌▐.DU██^[""ⁿ       -╒▌
▀█▄█`▌ ░M▀ ▌▐ Å£╝╝█╜%≈═╓""w   ⁿ⌐ █
`▀▄▀`▌ ▌█▐⌐║▐UW╖██%≤═░*─    =z ▄Γ
╙██╙▄▌█  ▌Å╛╣██╨%╤ƒⁿ=    -` ▄┘
█▌╢▓▌▌ W £6█╤,"ⁿ `   ▄≡▀▀▀
█"█▌▌╟Å╓█╓█▀%`    ▄▀
╙▌██`▒U▓U█%╗*     █
▌╫║ ▌ÅÅ║▀╛¬`      `"█
▌╫  ╫╟ █▄     ~╦%▒╥4^
▌▌  "M█ `▀╕ X╕"╗▄▀^
█▌   ╓M   ╙▀e▀▀^
╙██▄▄▀
^^

running install
Remove xonsh/parser_table.py
Building lexer and parser tables.
Traceback (most recent call last):
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parsers/base.py", line 6, in <module>
from ply import yacc
ImportError: No module named 'ply'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 182, in <module>
main()
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 178, in main
setup(**skw)
File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/distutils/core.py", line 149, in setup
dist.run_commands()
File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/Users/AlexCory/.pyenv/versions/3.4.0/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 92, in run
build_tables()
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/setup.py", line 53, in build_tables
from xonsh.parser import Parser
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parser.py", line 6, in <module>
from xonsh.parsers.v34 import Parser
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parsers/v34.py", line 4, in <module>
from xonsh.parsers.base import BaseParser
File "/private/var/folders/44/9l__szwj0q1d8j2cp8bhmr1r0000gn/T/pip-build-w02yr9u1/xonsh/xonsh/parsers/base.py", line 8, in <module>
from xonsh.ply import yacc
ImportError: No module named 'xonsh.ply'

# Fixed code
def print_exception(msg=None):
    """Print exceptions with/without traceback."""
    env = getattr(builtins, "__xonsh_env__", os.environ)
    if "XONSH_SHOW_TRACEBACK" not in env:
        sys.stderr.write(
            "xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True\n"
        )
    if env.get("XONSH_SHOW_TRACEBACK", False):
        traceback.print_exc()
    else:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        exception_only = traceback.format_exception_only(exc_type, exc_value)
        sys.stderr.write("".join(exception_only))
    if msg:
        msg = msg if msg.endswith("\n") else msg + "\n"
        sys.stderr.write(msg)