Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic python code formatting in sublime

I am trying to find some package that would auto format python code when using sublime.

There is PythonTidy, but when I use PackageController it says install completed but the package is not installed (does not appear in preferences).

I did try following the instructions in: https://github.com/witsch/SublimePythonTidy

and while i "pip installed" the package in python, sublime would not load, throwing:

terminate called after throwing an instance of 'boost::python::error_already_set'
/usr/bin/subl: line 3: 12415 Aborted                 
/usr/lib/sublime-text-2/sublime_text --class=sublime-text-2 "$@"

How would I go about installing this without PackageController, or alternatively, can anyone recommend another package?

like image 210
eran Avatar asked Jul 24 '12 09:07

eran


People also ask

How do I beautify the code in Sublime Text?

Beautify on Save sublime-settings : Ctrl+Shift+P or Cmd+Shift+P in Linux/Windows/OS X.

How do I change the format of Sublime Text?

Just select all lines ( CTRL + A ) and then from the menu select Edit → Line → Reindent. This will work if your file is saved with an extension that contains HTML like . html or . php .


2 Answers

ctrl+shift+P then Package Control: Install Package Look for Python PEP8 Autoformat and install it.

like image 190
Aquil Abbas Avatar answered Sep 19 '22 15:09

Aquil Abbas


Try doing the following in command line (a bit brute force):

  1. Navigate into the Packages/PythonTidy folder,
    usually ~/.config/sublime-text-2/Packages/PythonTidy
    or ~/.config/sublime-text-2/Packages/SublimePythonTidy
    • If it's non-existent reinstalling using Package Control
  2. Inside there should be another PythonTidy folder (which in your case will be empty).
    Don't get into it, just check it is empty.
  3. Run git clone https://github.com/witsch/PythonTidy.git
  4. Restart sublime and check the console for errors (View -> Show Console)

P.S. If you are unable to start Sublime do a:

sudo pip uninstall PythonTidy

Then retry what I wrote above.

like image 25
Ofir Farchy Avatar answered Sep 19 '22 15:09

Ofir Farchy