I've lost count on how many articles I've read both here on SO and elsewhere, but even after trying all suggestions I've had no success, so I decided to post my specific question here.
I'm on OSX (10.9), I have a Python 2.7 installation on a virtualenv (besides the global one) and Aptana Studio 3. I've tried all sorts of set ups, but I got to my current configuration by doing:
File > Import > General – Existing folder as new project
I then right-clicked the project directory and selected PyDev > Set as Django Project. I chose my manage.py and settings file.
Then I went on to Properties > PyDev – Interpreter/Grammar
and clicked the hyperlink to configure an interpreter not listed. I selected the python file in my virtual environment. I was prompted with the following list of folders to choose:
If I click "apply" without changing the default, I get the following error:
If I proceed anyway, I get all sorts of import errors for standard library packages/modules (e.g. json). I went and checked the lib folder in my virtualenv python installation and indeed these packages/modules were not present, which makes me even more confused about how virtualenv works (I hate these configuration things and I admit that for a long time I have avoided them whenever I could, collaborating to the maintenance of my ignorance). I have virtualenvswrapper installed. workon env_name
works perfectly, the pip installations go to the correct site-packages, but the standard library seems to be being accessed in the global python.
Anyway, I therefore included the global python lib folder:
I then went to Properties > PyDev – PYTHONPATH > Source folders tab > Add source folder
, selected the root of my Django project and clicked Apply.
I went to Aptana Studio 3 > Settings… > PyDev > Code Analysis
and configured it:
RESULT:
Certain things, like method( self ):
(notice the spaces) are corrected on save. I don't get any PEP8 warnings for many other stuff though, like dict[ 'key' ]
(extra spaces again), more than 80 characters per line etc.
I also get errors on relative imports (e.g. from ..utils import *
) and consequently all lines that use the imported values.
What could I possibly be doing wrong??
Although I haven't completely solved my problem, I'm posting this as an answer because it does achieve what the title asks for.
I reinstalled Aptana and instead of importing an existing folder as project I created a Django project (New > Project > PyDev Django Project
) and replaced the default new directory with my project's root. IT WORKED. I'm getting PEP8 warnings now!
There are caveats, however :
I don't know what this "create project" wizard does differently behind the scenes but as I feared it messed up with my files somehow. A git status
showed almost everything deleted and a lot untracked files. I cleaned it up with a git checkout -- <project root>
and git clean -f -d
. That solved the problem and the PEP8 warnings are still showing.
The second problem is that relative imports are broken. I have a from ..utils import *
for example. There are no error or warning on this line itself, but I get false "Undefined variable" erros in every line that uses something from this import.
According to this issue, it seems to be an open, unresolved problem with PyDev.
According to the PyDev relase history, however, Release 2.2 "Fixed issue with relative import with wildcards", which makes me very confused.
For the moment I guess I will simply hide "undefined variable" errors, since these will be caught when I actually run the code anyway. But the whole point of using an IDE is having features that catch these errors beforehand, so if anybody has some light to shed on this issue it would certainly be very appreciated.
PS: The scenario is exactly the same in LiClipse. PEP8 works now but relative imports lead to "Undefined variable" errors.
UPDATE
Here's a screenshot of the situation: