New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shell_plus --notebook not working in 1.7 #526
Comments
Thanks for reporting the problem. But it seems to work for me, when I create a new project with Django 1.7 and work with models in the IPython notebook. Which version of django-extensions are you using ? (use the latest git version to be sure this is not fixed already) If problem still exists; please create a reproducible case (step-by-step guide + tarball with a full example which fails and requirements.txt file) for developers to start identifying the root cause and fixing it. (Please reopen this ticket at that point) |
FYI, I got this problem today. I installed django-extensions on a Ubuntu 14.04 using It worked after following @trbs's comment above (using latest git version). |
After 1.4.4 in the git version we only have changes to @paulochf if you install 1.4.4 again do you get the problem back ? |
Please follow me, I don't know if I did this right. To remove the installed version from repo: If I did this right, so no, I didn't get the problem back. I reran my working note from yesterday and it didn't show that error again. As I don't know if the |
Looks sound to me. The only way to check if But I won't expect any real differences from those... the error indicates that Django is not properly initialized, this should be fixed for From what I can see from the traceback above the error is raised only when executing code in the notebook ? If that's the case then maybe something is not initializing Django correctly in the running notebook kernel. It's good to check the logs and make sure you see this line:
Because that extension will make sure that |
For the sake of debugging, I did a clean install again. I looked for any files after running a
I checked the versions here: Python 2.7.6, Django 1.6.1 (for my surprise, I thought that was 1.7!). Well, everything ok, then. Thanks! |
@trbs, the history ain't over! After I realize I was using Django 1.6.1, I updated it to 1.7 cleanly (uninstall 1.6, install 1.7). Then, when I went back to notebook, I got this error again. |
Any change you can give me a install guide I can follow to reproduce this on my machines ? |
Sure, @trbs. Please let me know if you want some specifics. sudo apt-get install ipython-notebook
sudo pip install Django django-extensions
# create django project with MySQL
# create some model
# add one row in DB table
python manage.py shell_plus --notebook Then in notebook: from project.models import Model
Model.objects.get(id=1)
# the error |
(Working) Test Case: $ virtualenv test526
New python executable in test526/bin/python2.7
Also creating executable in test526/bin/python
Installing setuptools, pip...done.
$ cd test526
$ source bin/activate
$ pip install ipython pyzmq jinja2 tornado
$ pip install Django django-extensions
# follow the configuration guide for shell_plus --notebook at http://django-extensions.readthedocs.org/en/latest/shell_plus.html#configuration
$ django-admin startproject ham
$ cd ham
$ ./manage.py syncdb
$ ./manage.py startapp eggs
$ cat > eggs/models.py << EOF
from django.db import models
class Egg(models.Model):
size = models.IntegerField(default=1)
EOF
# ham/settings.py
# - add django-extensions to INSTALLED_APPS
# - add eggs to INSTALLED_APPS
# - add IPYTHON_ARGUMENTS = ['--ext', 'django_extensions.management.notebook_extension', '--debug']
$ ./manage.py makemigrations
$ ./manage.py migrate
$ pip freeze -l
Django==1.7
Jinja2==2.7.3
MarkupSafe==0.23
backports.ssl-match-hostname==3.4.0.2
certifi==14.05.14
django-extensions==1.4.5
gnureadline==6.3.3
ipython==2.3.0
pyzmq==14.4.0
six==1.8.0
tornado==4.0.2
./manage.py shell_plus --notebook In the notebook: # no need to import the model Egg here since shell_plus did that for us.
Egg.objects.get(pk=0) Notes:
BAD: c = get_config()
c.InteractiveShellApp.extensions = [
'some.extension',
] GOOD: c = get_config()
c.InteractiveShellApp.extensions.append('some.extension') Follow Up in Django-Extensions Looked a bit into IPython and could not find an easier way that would guarantee the extensions (or something similar) gets loaded since the notebook is a separate process it does not help to run In b165647 we now give a fairly big warning when we startup If somebody is willing to make a PR for the documentation to try to explain this more clearly and explicitly it would be much appreciated. |
The test case worked. Then, in another terminal, I did I don't know what part was missing here.
edit: I commented As I don't know well IPython's configurations neither virtualenv, I don't know how to help more. |
So long I have used this, today I was trying to use it again and it wasn't loading my modules. After some tests, I realized that notebooks located at mydjangoproject/ loads modules correctly, but inside other folders (i.e. mydjangoproject/notebooks , for the sake of code organization) did not. Is there any solution for this issue? Thanks! |
Sorry for the moment the only solution is to make sure the notebook server is started from the project directory. |
Sorry for the late reply. @trbs, you mean running Because it's not the case.
Now I'm on Python 3.4.3, Django 1.8.3 and django-extensions 1.5.5 . |
One more thing. I'm not getting select_related() to work. Individual models does work, but using select_related() one with ForeignKey isn't. Using Django shell works normally. Using an extended test based on @trbs above: Note: using Python 3.4.3, Django 1.8.3 and django-extensions 1.5.5 .
then create some data
Then try to use select_related()
Thanks! |
For completeness, the error also occurs when trying to run SomeModel.some_many_to_many_field.all(), when shell runs it normally. |
@paulochf Your example works for me... it's also strange that something like Tested with Python 2.7:
|
Hey @trbs, I'm on Python 3.4.3, Django 1.8.3 and django-extensions 1.5.5 . I can't say nothing about Python 2.7 . Edit: didn't work either.Should I open another issue for Python 3/Django 1.8 or we can continue to discuss this here? |
Was dealing with this yesterday. Putting the following in my jupyter notebook before all the model imports helped circumvent and get back to fiddling: import os, django
django.setup() Relevant ModulesDjango==1.10.1 ipykernel==4.6.1 jupyter==1.0.0 |
If the settings file is at
|
from docs looks like there's a new setup() method.
The text was updated successfully, but these errors were encountered: