How to integrate pep8.py in Eclipse?
Solution 1:
As of PyDev 2.3.0, pep8
is integrated in PyDev by default, even shipping with a default version of it.
Open Window > Preferences
It must be enabled in PyDev > Editor > Code Analysis > pep8.py
Errors/Warnings should be shown as markers (as other things in the regular code analysis).
In the event a file is not analyzed, see https://stackoverflow.com/a/31001619/832230.
Solution 2:
I don't know how to integrate it for whole project, but I have used it as an external tool to analyze an individual file.
Note that the pycodestyle
package is the official replacement for and is the newer version of the pep8
package. To install it, run:
$ sudo pip install --upgrade pycodestyle
Next, in Eclipse:
- Select Run-External Tools-External Tools Configurations...
- Select Program root node.
- Press New launch configuration button.
- Enter Name for your launch configuration. I use
pycodestyle
. -
Fill following fields:
Location --
${system_path:pycodestyle}
Working directory --
${container_loc}
Arguments --
"${resource_name}"
(This uses the currently active file.)
Go to Common tab and confirm that the Allocate Console checkbox is checked.
A benefit of this approach is that you can use a very up-to-date version of the package, and are not limited to the old version included with PyDev. And if you are curious about setting up pylint
in a similar manner, see this answer.
Solution 3:
- Open your Eclipse
- Go to Help and select Install New Software
- Click the Add button and a "Add Repository" Dialog box will appear
- You can use any name you like for it. (I used PyDev)
- For the location, enter "http://pydev.org/updates"
- Click Ok.
- You are now in the process of installation. Just wait for it to finish.
- After the installation, close Eclipse and Open it again.
- Now that PyDev is installed in your Eclipse, go to Window->Preferences
- Choose PyDev->Editor->Code Analysis
- Go to pep8.py tab
- Choose the radio button for warning and click Ok.
That's it. Your Eclipse IDE is now integrated with PEP8. To run pep8.py automatically, right click on your project editor. Choose PyDev and click "code analysis". In your problems tab in your workspace, you will see warnings that points to the line that you have made a violation in the PEP8 (if you have violated).
Solution 4:
CODE ANALYSIS :
In Eclipse (PyDev), if you want to code analysis using pep8 style then
Go to:Windows -> Preferences -> PyDev -> Editor -> Code Analysis -> pep8.py tab and select Warning click Apply and OK button.
In your python code if you validate pep8 coding style it will give you warning
AUTO CODE FORMATTING :
In Eclipse (PyDev), if you want to Auto Format python code using pep8 style then
Go to:Windows -> Preferences -> PyDev -> Editor -> Code Style -> Code Formatter -> click on check-box (Use autopep8.py for console formatting?) click Apply and OK button.
If you want to increase length of line(pep8 default is 79) below Use autopep8.py you can set parameter type --max-line-length=150
if you set max length to 150
If press auto-format shortcut ( Ctrl + Shift + f ) it will automatically format your python code like pep8 style
Solution 5:
That does not yet appear to be fully integrated into Pydev.
As suggested in this post,
[it] would require changing the code within pydev -- a flexible option would be adding preferences to let the user choose to which patterns he wants to match for creating hyperlinks (and saying which group in the match is the line and which one is the file)...
Or, you can try it hard-coded playing with: org.python.pydev.debug.ui.PythonConsoleLineTracker (should be pretty easy to grasp).
A request does exist for just that, but it seems to be still open 1 year after its creation...