views:

599

answers:

5

Hi! I'm doing my VERY first project using python/django/eclipse/pydev following this guide

http://docs.djangoproject.com/en/dev/intro/tutorial01/

My only addition is the use of Eclipse/pydev.

I'm getting many errors related to "Unresolved imports". I can remove the errors using "remove error markers" and my site runs perfect (I can browse it) but I want to get rid definitively of this problem since errors appear again after I removed them.

Any ideas?

EDIT

Using Ubuntu 9.1

+6  A: 

Check your pythonpath. You need to include the parent directory of django, usually Lib/site-packages.

Adam
Thanks Adam, I've added to PYTHONPATH /usr/lib/pymodules/python2.6/django/ (libs seems to be there) but no luck :-(
Timmy O' Tool
@Timmy Is /usr/lib/modules/python2.6/ in PYTHONPATH?
Adam
I don't have that path. I have /usr/lib/python2.6
Timmy O' Tool
add /usr/lib/pymodules/python2.6 into your PYTHONPATH, you want the directory that contains django to be in there
Adam
The latest comment from Adam solved my problem. You must have both site-packages and site-packages/django in your PYTHONPATH. (I have django in site-packages)
simao
+1  A: 

If you are facing problem of unused imports then I must say use Eclipse as a IDE as it is providing functionality to remove unused imports by pressing keys ctr+shift+O. Or In Eclipse there is plugin also available which is doing the same thing automatically when you save your code.You can get that plugin from eclipse plugin site easily and free of cost.

Rupeshit
+1  A: 

I was able to get rid of the import errors executing this cmd

sudo ln -s /usr/lib/pymodules/ /usr/lib/python2.6/pymodules

I was lucky, testing different things I could resolve it but I'm not sure why I have to do this and how I could avoid doing it.

Timmy O' Tool
+1  A: 

I'm on Mac OS X, but all I had to do was to add:

/Library/Python/2.6/site-packages

to my System PYTHONPATH (Found in: Preferences > Pydev > Interpreter - Python)

The equivalent for Ubuntu 10.04 would be:

/usr/lib/pymodules/python2.6

I'm guessing that the equivalent for Ubuntu 9.x could be:

/usr/lib/python2.6/site-packages

If it isn't and you're tired of looking, just upgrade to Ubuntu 10.04 and you should be fine.

Erik B
+1  A: 

"Unresolved imports" occur when Eclipse/Pydev does not know what you want to import. Check your Pydev settings in the Eclipse preferences > Interpreter Python. Your site-packages folder and things you want to import should be there in the Pythonpath.

Also see http://pydev.org/manual_101_interpreter.html

webjunkie