[Fixed]-Unresolved import: models

5đź‘Ť

âś…

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.

16đź‘Ť

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

👤Adam

6đź‘Ť

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

3đź‘Ť

“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

3đź‘Ť

Even if Lib/site-packages is added to the PYTHONPATH, this problem may happen when using modules from egg packages installed using easy_install. The problem with those, and that might actually depend on the easy_install version, is that by default they don’t get installed directly inside Lib/site-packages but rather under a folder containing the full package name and having the .egg suffix. For example: Lib/site-packages/django_celery-3.0.23-py2.7.egg

Each module coming from packages installed as above needs an individual entry in PYTHONPATH. If the packages are installed after PyDev has been installed on the system, the system PYTHONPATH needs to be updated in PyDev. That is done automatically by going to Window -> Preferences -> PyDev -> Select your intepreter -> in the python interpreters panel remove and re-add your current python interpreter (usually, this should be the python executable from the system). Then a PyDev restart (File -> Restart) should solve the “Unresolved import” errors.

2đź‘Ť

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

2đź‘Ť

In my case of the modules were dependent on setuptools-14.3.1 , which was causing all these problems. After installation of setuptools-14.3.1 rest of the modules automatically resolved.

👤Shakti

1đź‘Ť

I was having a single import error when working in PyDEV in eclipse.

I was importing it like

from xyz_module import abc

So I clicked “Ctl + 1” and “select Unresolved import error” in eclipse and it created a class
file in a python file.

It turned out that I had created an application called “xyz_module” and a “xyz_module.py” file (with the same name that is) and this was causing an import error. I changed the python file to a new name and this resolved the error.

👤ankitk

1đź‘Ť

I had the same error and none of the answers worked for me as there was no PYTHONPATH options under Window -> Preferences -> PyDev -> Python.

Instead I added PYTHONPATH setting in the menu:

Project -> PyDev-PYTHONPATH -> External Libraries -> Add Source folder

I added the path of site-packages like

/home/Documents/hcx/venv/lib/python3.5/site-packages

Now PyDev stopped complaining.

👤bhaskarc

Leave a comment