Pydev Django1.4 ImportError - django

I have an old Django project. I upgraded to Django 1.6 and I want to see if it still runs. I did all the upgrades like change url names, but I did not change the structure. It runs perfectly fine from the command line, but when I run it in Pydev I get
ImportError: Could not import settings 'project.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named project.settings
What can I do to run it in Pydev?

I have just experienced the same problem and the solution was to set the Django settings module in the project properties. Right click on the project, then click Properties, go to PyDev - Django and set the Django settings module text field's value to the desired settings file.

Related

Django Unable to Import Settings Module

I'm trying to host a simple Django app on AWS.
I can run it via the public DNS and runserver, but I can't seem to get the environment URL working.
I checked the log and it says "ImportError: Could not import settings 'AppName.settings'"
I've tried adding sys.path.append('/opt/python/current/app/ProjectName/AppName') to the WSGI file, but when I try to print out the sys.paths, it is not listed.
How can I fix this?
Thanks!
I think you need to import till project name like
sys.path.append('/opt/python/current/app/ProjectName')
That will ensure project directory is in pythonpath and you can import AppName from there.

Pycharm runserver error with custom settings.py files

just started using pycharm on a existing project, and having difficulty using the run/debug configurations in order to run the test server. The issue stems from their being no settings.py module as standard in django projects. Instead there is settings_base.py and then two different settings modules (settings_live.py and settings_test.py) that extend it by using 'from settings_base import *'. This causes manage.py to fail when running runserver because it can't find settings.py.
In the Django Support settings I have set the project root, and set Settings to settings_test.py however this has not helped. In the Django server run configuration I have setup I also have...
DJANGO_SETTINGS_MODULE=settings_test
... in the Environment Variables section. However when I use runserver it still says
Error: Can't find the file 'settings.py' in the directory containing '/home/pete/Projects/the_project/manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)
I tried wrapping the entire settings_test.py module in a try/except to see if it really was an import error, however it did not seem to work. Is there something I am missing?
Maybe you should try adding --settings=settings_test to the "Additional options" in your PyCharm Run configuration and make sure that "Working directory" points to correct path.

Eclipse+PyDev: pydev can't find django.contrib.messages

When, from Eclipse, i run my django project, it throws
ImportError django.contrib.messages: No module named messages
Furthermore, in django consolle import django.contrib works fine, it throws
ImportError: No module named messages
Why?
In my django folder, where the python interpreter of pydev points, there is ./contrib/messages folder, so i don't understand why it can't find django.contrib.messages
I have resolved deleting old version of django that was in /usr/lib/pymodules/python2.6/
and reinstalling django.

Eclipse/PyDev/Django Import Requires Project Name

Developing a project in Django with my IDE setup as Eclipse with PyDev. The following import statement:
from polls.models import Poll, Choice
works when running the project from the command line via:
python manage.py runserver
However, built in error-checking with Eclipse fails to find polls.models ("unresolved import Port"). I can fix this by adding the project name before the class and then running this. That is, make the import statement:
from projectName.polls.models import Poll, Choice
The issue is that I'm collaborating on the project and can't do this.
Question is: Is there a way to have Eclipse auto-detect or assume the projectName from the import statement?
Using projectName on import statements is not a good idea.
When working with django/python start to use virtualenv. Especially when working with eclipse/pydev. You can than configure a new interpreter for every virtualenv. Just add the virtualenv to the list of interpreters under "Preferences > PyDev > Interpreter - Python" and be sure to add your djangoproject root to the PYTHONPATH on the same preferences page.
This is essentially what django does for you when running from the command line.

Configuration error in django

I am using django with mod_python (I know it is deprecated -- I am just doing this for an exercise), and am getting the following error --
"Could not import project.views. Error was: No module named app.models"
I am getting the 'No module named app.models" in several other places as well. My syncdb is working fine, and if I go into the manage.py shell I can import the models fine. Why is this occurring and what do I need to change? Thank you.
You should use absolute imports everywhere. If your project is structured like so:
/project/settings.py
/project/app/models.py
/project/app/views.py
In INSTALLED_APPS you would use project.app. In app you'd import your models into views: import project.app.models, etc. Alternately you can try adjusting your PYTHONPATH so your imports work. When you run ./manage.py you are in your project folder, and Python automatically adds it to the PYTHONPATH. This doesn't happen automatically in most deployment scenarios (mod_python or other wise).