0

I'm trying to understand what the issue is:

I'm trying to import a module:

from main.models import Main
from django.contrib import admin

admin.site.register(Main)

However, when I attempt to hit the admin site, I get a django error page:

ImportError at /admin/
cannot import name Main

I noticed that it provides a dump of the **Python Path:**

Python Path:    ['/Users/brian/src/SampleApp/src/SampleApp', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode']

However, what I don't understand is where is this Python Path set?

doing an export PYTHONPATH returns nothing as it is not set in the environmental variables.

I need to import a module which is located in /Users/brian/src/SampleApp/src/SampleApp/main/models.py

Thanks

2 Answers 2

4

PYTHONPATH can be accessed via:

import sys
print sys.path

A bit of debugging to try would be to use:

from main import models
from django.contrib import admin

admin.site.register(models.Main)

and see if that gives you any more information.

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

Comments

1

Do you have an __init__.py in /Users/brian/src/SampleApp/src/SampleApp/main/? This is required for the main directory to be considered for the search. An empty __init__.py will do.

You might also verify that Main is defined in there. Does a plain import main.models work?

2 Comments

Yes I have an empty init.py there... stupid me, Main is not there . that was it. Thanks.
any idea where the PYTHONPATH is set ?

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.