Daniel Daniel - 4 months ago 13
Python Question

django import search path

I'm configuring autocompletion for python and django in vim. One of the problems is that I need to set an environment variable DJANGO_SETTINGS_MODULE=myapp.settings. The django tutorial states that


The value of DJANGO_SETTINGS_MODULE
should be in Python path syntax, e.g.
mysite.settings. Note that the
settings module should be on the
Python import search path.


http://docs.djangoproject.com/en/dev/topics/settings/

But if your app isn't in the import search path, how do you make it so that it is?

Answer

Three choices.

  1. Set PYTHONPATH environment variable to include your application's directory. Be sure it has an __init__.py file.

  2. Create a .pth file in site-packages to point to your application's directory.

  3. Install your application in site-packages.

These are the three ways of "installing" a Python module. Read about the site module for more information.