Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't Django use IPython?

Tags:

(myvenv)me:src orokusaki$ python manage.py shell -i ipython
Python 2.7.2 (default, Jun 16 2012, 12:38:40) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> while True:
...     pass  # :(
...

I have IPython installed globally, and it works while this myvenv virtualenv is activated just fine. However, if I start the Django shell (with or without -i), it won't use IPython. I've never had this problem before.

Note: django-admin.py vs manage.py won't make a difference.

like image 966
orokusaki Avatar asked Jan 31 '13 01:01

orokusaki


2 Answers

Try installing it into virtualenv! :-)

like image 86
Mike Repass Avatar answered Oct 09 '22 09:10

Mike Repass


I love iPython but don't like installing it in all my virtualenvs, and I've found a good solution to allow for that. Instead of using python manage.py shell, you can just use the system iPython directly.

In order for this to work properly, you need to set the DJANGO_SETTINGS_MODULE so that it corresponds to your project.

export DJANGO_SETTINGS_MODULE=yourproject.settings

If this is your only Django project, the easiest solution is to add that line to your .bashrc.

If you have several Django projects and want to avoid having to change the variable every time you switch between projects, you can add that export line above tailored to each project to the postactivate scripts of all your Django virtualenvs. For me, the postactivate script is at ~/.virtualenvs/myvenv/bin/postactivate.

like image 33
Arash Ghoreyshi Avatar answered Oct 09 '22 08:10

Arash Ghoreyshi