tags:

views:

56

answers:

2

I'm having an issue with a failing import statement, it is called by a manage.py command. It works in the manage.py shell. It also recently worked, i've tried to retrace my steps to no avail. Any advice?

A: 

Your question does not have enough information to answer definitively, but I can at least offer some hints to debug the problem.

Understand the import statement

Read and understand the documentation for the import statement for your version of Python..

Check the Python path

One key step towards debugging any import problem is to ensure that your module is available on the python path. Add the following code to the code that's having the problem:

import sys
print "\n".join( sys.path )

Somewhere in that list must be the directory tree that contains your module. If it's not there, you'll either have to reference your module differently, or add the right directory to the python path. Keep in mind that Python is a dynamic language -- the python path can be changed as a program runs, and what matters is the state of the python path at the time of them first import of a module.

Remember to add an __init__.py file to your packages

It must be present, even if empty.

Search StackOverflow before asking a question

A simple search for [python] import]2 or [django] import]3 may turn up a similar question, with answers that fit your situation.

Craig Trader