18

I am using Spyder 2.3.1 and python(x, y).

In the preferences of Spyder you can activate "Style analysis". This is quite nice, but I want to increase the max. tolerable line length. The standard setting for PEP8 is 79 characters. This can be changed through a setup.cfg with the content:

[pep8]
max-line-length = 99

This can be read here: http://pep8.readthedocs.org/en/latest/intro.html#related-tools

Where do I put a setup.cfg so Spyder/PEP8 will recognize my new limit? Or is there an other way to set this limit or to ignore E501 (line to long)? Just setting "Show vertical line after 99 characters" in Spyder does not help.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
venti
  • 489
  • 3
  • 6
  • 12

6 Answers6

18

According to the link cited by @Werner:

http://pep8.readthedocs.org/en/latest/intro.html#configuration

what you need to do is to create a file called ~/.config/pep8 (On Linux/Mac) or ~/.pep8 (on Windows), and add these lines to it:

[pep8]
max-line-length = 99

I tested it in Spyder and it works as expected.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124
  • 6
    Thanks. I had some problems at first with that answer, and a want to share some help: A) Where is ~/ under Windows: I found it with a console window: "cd /d "%HOMEDRIVE%%HOMEPATH%"" B) How to create a file with a name, which starts with a .dot unter windows: It is not possible to use the explorer for that, try "echo test >.pep8" This will create a file with the name .pep8 See [link](https://superuser.com/questions/64471/create-rename-a-file-folder-that-begins-with-a-dot-in-windows/406758#406758?newreg=1715da3c190e481a8bdc92c6e40b1d3c) – venti Oct 31 '14 at 12:37
  • and [link](http://superuser.com/questions/332871/what-is-the-equivalent-of-linuxs-tilde-in-windows) for home dir – venti Oct 31 '14 at 12:41
  • 1
    That's really ugly! If you want, we can include an option in Spyder (I'm its current maintanter) to change that pep8 parameter through our Preferences pane. Just open an issue in our [issue tracker](http://code.google.com/p/spyderlib/issues/list) so we don't forget to do it in a future release :-) – Carlos Cordoba Oct 31 '14 at 18:24
  • 5
    I have some other programs set up which set a HOME environment variable so to find what Spyder thinks is my home the folder, I did `import os; os.path.expanduser('~')` in Spyder. – Justin Harris May 17 '15 at 00:09
  • 6
    after updating to spyder 3.2.3 this does no longer work. An alternative approach is to change the hardcoded MAX_LINE_LENGTH=79 in pycodestyle.py. – Stian Sep 22 '17 at 07:33
  • @Stian That seems ugly and non-intuitive. Is there no other way to do this? – Derek Apr 08 '18 at 08:33
  • In Spyder 2.3.8 under Ubuntu 14.04, this setting makes no difference when I "Run Static Code Analysis" (F8). What else needs to be changed? – Derek Apr 08 '18 at 08:42
  • (I also tried approach from http://pep8.readthedocs.io/en/latest/intro.html#configuration but that does not work either.) – Derek Apr 08 '18 at 08:50
  • Running Spyder 3.3.6 on a Mac, and I am not able to implement this. Anybody here able to successfully implement this? – Raul Torres Nov 07 '19 at 00:12
9

Inspired by Minh's comment I've been able to make this work for spyder 3.8 by doing the following. Find out the ~ directory using

import os; os.path.expanduser('~')

(see remark ofJustin Harris)

Then add a file to the ~ directory called .pycodestyle containing:

[pycodestyle]
max-line-length = 99

(see Carlos Cordoba's answer)

Restart spyder [EDIT: according to the comments below this is not needed]. This is actually just combining most of the above remarks and answers.

Goosebumps
  • 919
  • 2
  • 14
  • 27
  • A more complete answer of what what the discussion happened in the 'accepted answer'. I didn't even have to restart spyder and it worked. – Hansang Jul 29 '18 at 00:40
  • See [this](https://stackoverflow.com/a/53325989/1653453) answer for another location. – Ivan Oct 21 '19 at 09:23
3

If you are user "myname" using conda, in environment "myenv" try to edit the file: /home/myname/miniconda3/envs/myenv/lib/python3.7/site-packages/pycodestyle.py and change MAX_LINE_LENGTH=79 to MAX_LINE_LENGTH=100, for example. Worked for my Spyder 3.3.6.

2

References to "pep8" are obsolete. The package has been renamed to "pycodestyle".

1

The tox.ini with a pep8 section or a setup.cfg at the project level should do.

http://pep8.readthedocs.org/en/latest/intro.html#configuration

Werner
  • 2,086
  • 1
  • 15
  • 14
0

using the Spyder 4.0.0.dev0 went to my ~/.config/spyder.ini, ensured that my spyder application was not running change the dictionary value 'maxLineLength': 100 from 'maxLineLength': 79.

Started my app and it worked now if you edit the file while your spyder app is running upon shutting down it will overwrite what ever is in the ~/.config/spyder.ini.

Ensure it is not running and make the necessary changes

zadstofun
  • 1
  • 1