I keep running into problems with Unresolved imports in my Django project (in Eclipse w/ PyDev). After googling for a while on a given issue I can generally find the right thing to add to PYTHONPATH to solve the problem. But it seems like I’m missing some concept or process by which I can definitively say “obviously there is what I should add to get that thing to import properly”. What makes this more frustrating is that I’m just following the basic Django tutorial, so I’d expect these things to be simply dealt with. In Java world it is usually pretty clear because I can find out exactly what library a particular package is coming from, download it and add it to build path. What is the equivalent concept in Python/Django world?
I am not looking to solve a specific problem here, but rather to know what are the steps to follow, or where to look it up, or the concept I am missing. Or possibly to find out that there is not one and its always guesswork…
I am running on Ubuntu 10.10, Python 2.6
From your question I assume that you are quite new to Python, so let’s start at the beginning.
My advice would be to look at the traceback that Django generates and search for a line which looks like this: “ImportError: No module named somemodule”. This tells you the name of the missing module.
Once you know the name of the module you can try to see if the missing module is listed in PyPi (Python Package Index) by using easy_install.
Try running:
If you’re lucky then the missing module will be installed into your python installation’s site-packages directory (possibly /usr/lib/python2.6/site-packages, depending on where your python is installed). The site-packages directory is where all 3rd party modules should be installed to, and all modules in this directory are always import-able and on the PYTHONPATH.
It’s possible that your code is trying to import something that is not available on PyPi, in which case Google is your best option :p
p.s.
If easy_install doesn’t work (or it’s missing) then it’s possible that you don’t have the setuptools python module installed, which you can get from here: http://pypi.python.org/pypi/setuptools