How do I set the maximum line length in PyCharm?

PythonPycharmPep8

Python Problem Overview


I am using PyCharm on Windows and want to change the settings to limit the maximum line length to 79 characters, as opposed to the default limit of 120 characters.

Where can I change the maximum amount of characters per line in PyCharm?

Python Solutions


Solution 1 - Python

Here is screenshot of my Pycharm. Required settings is in following path: File -> Settings -> Editor -> Code Style -> General: Right margin (columns)

Pycharm 4 Settings Screenshot

Solution 2 - Python

For PyCharm 2018.1 on Mac:

Preferences (āŒ˜+,), then Editor -> Code Style:

enter image description here

For PyCharm 2018.3 on Windows:

File -> Settings (Ctrl+Alt+S), then Editor -> Code Style:

To follow PEP-8 set Hard wrap at to 80.

Solution 3 - Python

For PyCharm 4

File >> Settings >> Editor >> Code Style: Right margin (columns)

suggestion: Take a look at other options in that tab, they're very helpful

Solution 4 - Python

You can even set a separate right margin for HTML. Under the specified path:

File >> Settings >> Editor >> Code Style >> HTML >> Other Tab >> Right margin (columns)

This is very useful because generally HTML and JS may be usually long in one line than Python. :)

Solution 5 - Python

For anyone, or myself if I reload my machine, who this is not working for when you do a code reformat there is an additional option to check under editor->code style->python : ensure right margin is not exceeded. Once this was selected the reformat would work.

preference_highlighted

Solution 6 - Python

For PyCharm 2019.3.1, I see this.

enter image description here

Solution 7 - Python

For PyCharm 2021.x this did the trick for python: enter image description here

Solution 8 - Python

For PyCharm 2017

We can follow below: File >> Settings >> Editor >> Code Style.

Then provide values for Hard Wrap & Visual Guides for wrapping while typing, tick the checkbox.

NB: look at other tabs as well, viz. Python, HTML, JSON etc.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnsuman BebartaView Question on Stackoverflow
Solution 1 - PythonAlex G.P.View Answer on Stackoverflow
Solution 2 - PythonlmiguelvargasfView Answer on Stackoverflow
Solution 3 - PythonMarco SanchezView Answer on Stackoverflow
Solution 4 - PythonandyView Answer on Stackoverflow
Solution 5 - PythonSteve StachaView Answer on Stackoverflow
Solution 6 - PythonZhefengJinView Answer on Stackoverflow
Solution 7 - PythonHeyManView Answer on Stackoverflow
Solution 8 - PythonAB AbhiView Answer on Stackoverflow