0

Eclipse Neon (4.6.0).

PyDev for Eclipse 5.1.2.201606231256

I have created a Django project:

File / New / Project / PyDev Django project

Selected "Add project directory to the PYTHONPATH".

Now I have this folder structure.

(django_comments) michael@ThinkPad:~/workspace/formsets$ tree
.
└── formsets
    ├── db.sqlite3
    ├── formsets
    │   ├── __init__.py
    │   ├── __pycache__
    │   │   ├── __init__.cpython-35.pyc
    │   │   ├── settings.cpython-35.pyc
    │   │   ├── urls.cpython-35.pyc
    │   │   └── wsgi.cpython-35.pyc
    │   ├── settings.py
    │   ├── urls.py
    │   └── wsgi.py
    ├── home_page
    │   ├── admin.py
    │   ├── apps.py
    │   ├── __init__.py
    │   ├── migrations
    │   │   ├── __init__.py
    │   │   └── __pycache__
    │   │       └── __init__.cpython-35.pyc
    │   ├── models.py
    │   ├── __pycache__
    │   │   ├── admin.cpython-35.pyc
    │   │   ├── __init__.cpython-35.pyc
    │   │   ├── models.cpython-35.pyc
    │   │   └── views.cpython-35.pyc
    │   ├── templates
    │   │   └── home_page
    │   │       └── home_page.html
    │   ├── tests.py
    │   └── views.py
    └── manage.py

In prjoect properties in PyDev-PYTHONPATH at the tab Source Folders I have: /${PROJECT_DIR_NAME}

In home_page/views.py I have created HomePageView. And in urls.py I would like to import it:

from home_page.views import HomePageView

The problem is: 1) HomePageView is underlined with red line. Error is Unresolved import: HomePageView.

2) Code completion is not working.

By the way, if I run the project, it works. That HomePageView shows what was expected.

Could you help me understand what have I done wrongly.

Michael
  • 4,273
  • 3
  • 40
  • 69
  • Is eclipse aware of your virtualenv? I've had similar issues with different tools and that was the culprit. – theWanderer4865 Sep 23 '16 at 20:31
  • Yes, I user virtualenv. I'll try to change it (as I have several). – Michael Sep 23 '16 at 20:35
  • Changing virtualenv didn't help, unfortunately. – Michael Sep 23 '16 at 20:46
  • Changing it won't help: you'll need to see how to get eclipse to use the binaries in a virtualenv for your project. Edit: maybe this question would help? http://stackoverflow.com/questions/1145374/virtualenv-with-eclipse-galileo – theWanderer4865 Sep 23 '16 at 20:48

1 Answers1

0

Try to add a path to the directory where your manage.py file is located. So I'm guessing it to add:

/${PROJECT_DIR_NAME}/formsets

zubhav
  • 1,519
  • 1
  • 13
  • 19
  • Working. I'll gladly accept it. Could you comment a bit. As far as I remember, in bygone days when creating project as mentioned above, Eclipse created project with structure: formset/formset. That is two tiers. But now three tiers: formset/formset/formset. This must be somehow connected with the problem. – Michael Sep 23 '16 at 23:25
  • I had a similar problem where I wasn't able to cmd + click to go to definition of a model/view. Knew it was something to do with PYTHONPATH and started to try and add different directories until I realised it worked when you point it at the src folder for that project. That is where PyDev is able to detect your file structure. Not sure about the Eclipse structure but that seems very strange. – zubhav Sep 23 '16 at 23:31