mikicz
mikicz

Reputation: 148

Strange characters in Django shell, arrowkeys not working

After doing nothing out of ordinary, my shell from Django is broken


    (virtulenv)miki@blablabla >>  python manage.py shell
    Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
    Type "copyright", "credits" or "license" for more information.

    IPython 2.3.1 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

    In [1]: 

It displays the signs for white space as these special chars, but as I look at the preview here, it's not displaying, I'm putting here a image of it... wrong prompt

However, that is not he only problem. The arrows and history is not working

In [1]: ^[[A^[[B^[[D^[[C

This happens in the plain shell as well:


    (virtulenv)miki@blablabla >>  python manage.py shell --plain
    Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
    [GCC 4.8.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>> ^[[A^[[B^[[D^[[C

I've tried installing readline and recompiling python.

Ideas?

Upvotes: 2

Views: 948

Answers (3)

Nour Wolf
Nour Wolf

Reputation: 2180

After suffering from the same issue for long time I found out that installing bpython or ipython did not only solve the problem, but also made my debugging-life much easier with their syntax highlighting, auto indentation, suggestions autocomplete and many other fancy stuff.

simply install bpython

pip install bpython

or ipython

pip install ipython

I personally recommend bpython over ipython as it is much lighter and just what you wanted.

Upvotes: 4

mikicz
mikicz

Reputation: 148

I figured it out...

Boss added this to settings, which causes it, because of encoding on production. I added the condition and set the enviroment variable on my computer and it's fixed...

if not os.environ.get("DISABLE_UTF8_REDEFINE"):
    sys.stdout = codecs.getwriter('utf8')(sys.stdout)
    sys.stderr = codecs.getwriter('utf8')(sys.stderr)

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798606

Your terminal is broken. The current value of $TERM, assuming there is one, does not match the terminal in use.

Upvotes: 0

Related Questions