Unresolved import: models

前端 未结 9 1066
星月不相逢
星月不相逢 2020-12-03 03:32

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 additi

相关标签:
9条回答
  • 2020-12-03 03:57

    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.

    0 讨论(0)
  • 2020-12-03 04:02

    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.

    0 讨论(0)
  • 2020-12-03 04:05

    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.

    0 讨论(0)
  • 2020-12-03 04:06

    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.

    0 讨论(0)
  • 2020-12-03 04:08

    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.

    0 讨论(0)
  • 2020-12-03 04:09

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

    0 讨论(0)
提交回复
热议问题