I can open an interactive shell from the command line, just not from PyDev inside Eclipse. Clicking through Django --> Shell with django environment
I get the following output:
import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python27\python.exe 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
PyDev console: using default backend (IPython not available).
from django.core import management;import carbon_factors.settings as settings;management.setup_environ(settings)
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setup_environ'
To try and resolve this I have updated PyDev to 3.2.0 with no change to the output. I'm using Django 1.6.
I have looked at the comment here which pointed me here. However the accepted answer seems to have already be built into Django/PyDev as the line it suggests to change in manage.py
is already changed.
To use it, do Ctrl+Alt+Enter (while in the PyDev editor) to: Open a console if there's no open console. Make an runfile of the current editor in the console (if no text is selected), so that its symbols are available for further experimentation.
In addition, manage.py is automatically created in each Django project. It does the same thing as django-admin but also sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project's settings.py file.
python manage.py shell starts up a regular version of the python interrupter but with the added environment. For example try executing your statements in the regular python interrupter rather than the django shell.
setup_environ
has been deprecated in Django 1.6. See here.
As far as I can tell, PyDev has hardcoded this method of starting a Django shell into the right click project -> "shell with Django environment" menu item. This is an issue that PyDev needs to address (hopefully by simplifying whatever they are doing under the hood with that command to just "python manage.py shell"!) I don't believe their menu command currently calls manage.py, which is why the other answers didn't work for you.
Option 1 As a hacky workaround, add "from django.conf import settings; settings.configure()" to the initial interpreter commands in Window->Preferences->PyDev->Interactive Console. You'll still see the error but at least you'll have your settings.
Option 2 In Window->Preferences->Interpreter->Environment tab, add an environment variable "DJANGO_SETTINGS_MODULE" with the Python dotted path to your settings file (exclude the '.py' at the end).
For the sake of having an up-to-date answer, this works fine for me with Django 1.8 and Eclipse Luna.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With