0

I'm using Eclipse/PyDev with Python2.7 for a project in Django. In one of my apps (say app1) I have a variables defined in models.py that have lists assigned to them. I'm failing to import these into models.py of another app (say app2). Say the project is called projectName.

projectName/app1/models.py

VARIABLE_NAME = (
    ('a', 'choice1'),
    ('b', 'choice2'),
)

projectName/app2/models.py

from projectName.app1.models import VARIABLE_NAME

I'm receiving an error from Eclipse of Unresolved Import: VARIABLE_NAME

Any ideas?

3 Answers 3

1

PyDev's Eclipse API does this for me too. It has troubles checking if from...import... style imports will actually resolve to a real import. This looks pretty normal to me. When you run the program, it will likely work. If not, it's more than likely an error on your part.

Sign up to request clarification or add additional context in comments.

Comments

1

I think the following is what's going on:

1) Eclipse sees you trying to import, but projectName is not a package (unless you added it explicitly) in sys.path, so it is being nice and complaining to you.

2) the problem is that projectName is not supposed to be a package; at least not yet. According to https://docs.djangoproject.com/en/dev/ref/django-admin/ , it says that "In addition, manage.py... puts your project’s package on sys.path."

Thus I would ignore the "error," even though Eclipse is technically correct that you cannot make that import. The point of the Django setup is when you do "python manage.py runserver" the projectName will actually be available, so everything is good. =)

Comments

1

Found a solution. This is a PYTHONPATH problem, as yanxhang pointed out. In Eclipse's Preferences, under PyDev > Interpreter, in the bottom window for System PYTHONPATH, make sure to add the folder that is the parent of your projectName and click apply. This allows for the projectName to resolve itself and all of its children.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.