User Tools

Site Tools


info:pycharm

Links

Comparisons

General Advantages

  • First usable comment/uncomment action (Ctrl+/) I've seen for CSS

Eclipse

Overall PyCharm seems somewhat snappier/lighter than Eclipse, though it's still a relatively heavyweight Java application.

  • Shows formatted docstrings, supports reStructuredText
  • Documentation shows inferred types of arguments and return, if known.
  • PyCharm works better with PyQt. It sounds like the only option in PyDev is to add PyQt4 as a "forced builtin", but of course it will have no completion (but I still haven't gotten even that to work properly).
    • It seems that PyCharm somehow generates "skeletons" for the shared libraries to allow for completion/docstrings (in PyQt4's case the docstrings show the valid signatures). From the look of the skeletons, I'm guessing that it imports the modules and introspects them, storing the results as a ".py" file.
    • PyDev seems to have some ability (less, perhaps, since it doesn't seem to work well with PyQt4?) to get completion information from shared libraries
      • Using SWIG with the "-builtin" option, PyDev seems to pick up the docstring for completion, resulting in better completion than if you had SWIG generate the pure-Python wrappers (in which case it would see *args, **kwargs). I'm not sure how that would work if the method was overloaded.

Wingware

Going by feature lists and videos; I haven't tried it yet (seems too expensive because it sounds like you're not allowed to use the "personal" version at work, and on top of that the personal version has less features).

  • Wingware shows documentation all the time in a pane. I tried to make PyCharm's quick documentation into a pane, but it doesn't seem to work right.
  • In Wingware, during debugging, the live runtime state is used to provide better code completion within the normal editor (not just in a debug console).
  • Wing IDE's debugger doesn't suppport Jython (or IronPython or PyPy)

Options to Possibly Change

NOTE: might want to try the "Settings Repository" plugin for sharing settings.

  • Inspections
    • Python: Redeclared names without usage (PyDev by default detects a "duplicated signature", but PyCharm misses such an error without this inspection; may now default on)
  • Python Integrated Tools (per project: not sure if you can set defaults for this)
    • Docstring format: reStructuredText
  • Python Template Languages
    • Template language
  • Editor → General
    • Honor "CamelHumps" word settings when selecting using double click (seems to affect underscores too; currently disabled, so double-click highlights an entire variable name)
    • Change font size (Zoom) with Ctrl+Mouse Wheel
    • Highlight usages
    • Strip trailing spaces on Save (I'm not sure what the default is)
    • Ensure line feed at file end on Save
    • Show quick doc on mouse move
  • Editor → Colors & Fonts
    • → Console Font
  • Editor → Code Style
    • Line separator (for new files): Unix
    • Right margin
  • Editor → Smart Keys
    • Indent pasted lines relative to caret location (enable)
    • Use "CamelHumps" words (seems to affect underscores too; currently enabled)
  • Editor → Appearance
    • Show whitespaces
  • Editor → Editor Tabs
    • Mark modified tabs with asterisk
  • Editor → File Encodings (under Default Settings)
    • IDE Encoding: UTF-8
    • Project Encoding: UTF-8
  • General
    • Reopen last project on startup?
  • Tools → SSH Terminal
    • Default encoding: UTF-8

Keymap

The Eclipse keymap is most familiar to me. But some of the keymap is weird; for example, I think I might prefer to switch Find and Replace back to Ctrl-F and Ctrl-H. And some of the keymap doesn't actually work, because keys are doubly-bound (e.g. Alt+Shift+X for Run).

From default keymap, some that I like:

  • Ctrl+P = Parameter Info
  • Ctrl+Alt+R = Run manage.py task…
  • Alt+Shift+Up = Move line up
  • Alt+Shift+Down = Move line down

Other changes to try:

  • Ctrl+Button2 (middle) = Add or Remove Caret (Alt mouse shortcuts are typically for moving windows in Linux)
  • Ctrl+Alt+C = Check In Project (replacing "Extract Constant", which I don't use very often)

shortcutFoo is a web application for practicing shortcuts in many applications, including PyCharm.

The "Key promoter" plugin will pop up to show the keyboard shortcut when you use the mouse for something (though it can get kind of annoying); it's configurable under Other Settings.

Live Templates

Main

def main():
    $END$

if __name__ == '__main__':
    main()

Cygwin Terminal

Under Tools→Terminal, the following "Shell path" seems to work for starting a Cygwin bash terminal instead of the regular cmd terminal:

C:\cygwin\bin\bash -c "/bin/xhere /bin/bash.exe"

I figured this out by looking at the registry entry added by the chere command.

zsh can be used instead (chere runs bash directly, then runs zsh under xhere):

C:\cygwin\bin\bash -c "/bin/xhere /bin/zsh.exe"

but the PyCharm terminal is doing something weird with the default grml prompt. Some things I tried so far, to no avail:

  • Setting the encoding 1)
  • Changing the console font 2)

With the babun shell, this runs, but doesn't start in the right directory:

"C:\Users\Sam\.babun\cygwin\bin\bash.exe" -c "/bin/xhere /bin/bash.exe"

Plugins

See also node.js for more Javascript/Node.js/web plugins.

  • Wrap to Column - "Wrap selected text to the specified column width. Similar to the Emacs command 'Fill Paragraph' and Vim's `gq` (format lines) command. A replacement for the native Intellij Fill Paragraph command, which hasn't ever worked correctly for me."

Notes

Type Inference

Sometimes PyCharm can figure out what type a variable is, but at other times you can give it some help.

It parses certain docstrings; if I remember correctly, it uses the parameter and return type annotations.

If you call isinstance, e.g. with an if block or assert statement (example: http://devnet.jetbrains.net/thread/436846?tstart=0):

question = form.save(commit=False)
assert isinstance(question, models.CategoryQuestion)

Virtualenv Base Directory

Set the WORKON_HOME environment variable to set the base directory for creating virtualenvs through PyCharm. This works on Windows too.

PyCharm Logs

Help menu → Show Log in File Manager

Usually in the system/log subdirectory of the PyCharm directory (e.g. ~/.PyCharm40).

Problems

  • Problems debugging when more than one Qt package (PyQt4/PyQt5/PySide) is installed in the interpreter: https://youtrack.jetbrains.com/issue/PY-21260
    • Workaround: "Since PyCharm 2017.1.1 one can define PyQt backend for debug session by setting environment variable PYDEVD_PYQT_MODE to 'pyqt4', 'pyqt5' or 'pyside'."
  • Debugging doesn't work in QThread: http://youtrack.jetbrains.com/issue/PY-4299
    • A commenter says that Wing IDE works with QThreads
    • Need to check to see if Eclipse PyDev works
  • IDEA-16709 - Mouse right-click context menu bad behavior under Linux (only when keymap is Eclipse-based)
    • The workaround is to remove the "Button3 Click" from the "Show Context Menu" action in the keymap
  • Wrong signature ("restored from __doc__") for some PyQt4 static methods like QtGui.QMessageBox.critical
  • PyCharm doesn't understand Makefile syntax (e.g. it inserts spaces)
    • Adding an EditorConfig file is a quick solution (support for EditorConfig is built in)
    • There is also a 3rd-party Makefile plugin available
  • The import auto-fix suggests packages I never want to import from (e.g. logging from IPython); I'd like to have a way to blacklist these

Bugs I reported/followed on the issue tracker:

PyQt4 Unresolved References

Summary: problem/bug with skeleton generation. Look for errors in event log, try to resolve, manually clear python stubs directory, try again.

Some virtualenvs work fine, some don't. Right now creating a new one is not working. I use this command:

mkvirtualenv --system-site-packages venvtest1

In PyCharm I have the following statement:

from PyQt4 import QtGui

When I add the interpreter in PyCharm, it underlines "QtGui" with the error "Unresolved reference 'QtGui'". Control-clicking on "PyQt4" takes me to the __init__.py in the system Python "site-packages" as expected, but not "QtGui" (as if the skeletons were not generated from the shared library). Creating a virtualenv from the PyCharm GUI gives the same unresolved references.

Some previously-created virtualenvs work fine; I can't see any obvious differences between them. Control-clicking on "QtGui" takes me to the generated skeleton under the ".PyCharm30" directory.

An error is given in the "Event Log" about failing to generate skeletons for one module, a CFFI module (generated shared library) not related to Qt. I can't seem to make it generate this error a second time except by creating a completely new virtualenv (deleting and recreating with the same name does not work, nor does "File → Invalidate Caches").

To see if it was a problem with the CFFI module, I removed the link from easy-install.pth and deleted the egg-link file. To get everything to rebuild, I had to clear out the ~/.PyCharm30/system/python_stubs directory. Then everything started working.

TODO: file a bug report if I can figure out a good way to explain how to reproduce. Or try to fix it in the source and submit a pull request (possibly with a corresponding bug report).

info/pycharm.txt · Last modified: 2017-06-26 20:13 by sam