• [PyCharm IDE]
 

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Table of Contents
typeflat
separatorpipe

Before you start…

  • Make sure that at least one Python interpreter, version from 2.4 to 3.4 is properly installed on your computer.
  • Mind that PyCharm is available in two editions: Community and Professional. The difference between the editions is explored in Edition Comparison Matrix.

Note that the download page contains installation instructions for the various platforms; these instructions may vary for the different operating systems.

Initial setup

If this is the very first time you launch your PyCharm, it will ask you several important questions:

...

Everything you do in PyCharm, is done within the context of a project. What is most interesting about PyCharm project management, is the possibility to open multiple projects in one frame. When you create a new project (

File →New Project
span
classshortcut
Wiki Markup
{span:class=shortcut}File →New Project{span}
), or open an existing one (File →Open
span
classshortcut
Wiki Markup
{span:class=shortcut}File →Open{span}
), PyCharm suggests you to choose which way you want the project to be opened: in a new window, in the same window after closing the previously opened project, or added to the previously opened project.

...

OK, your project is ready. Before you start working with it, just press 

Shift
span
classshortcut
Wiki Markup
{span:class=shortcut}Shift{span}
 twice. You’ll see a pop-up window that allows finding anything and jumping everywhere:

...

Same thing happens with the paths. If you have installed or upgraded libraries, it is a good idea to rescan the Python installation. Click the gear button located to the right of the project interpreter field, and choose

More
span
classshortcut
Wiki Markup
{span:class=shortcut}More{span}
. Then, in the Project Interpreters dialog, select the interpreter you want to view the paths for, click , and then, in the Interpreter Paths dialog, refresh packages :

...

But you can fine-tune — just click

Version Control
span
classshortcut
Wiki Markup
{span:class=shortcut}Version Control{span}
node in the Settings/Preferences dialog (Project Settings→Version Control
span
classshortcut
Wiki Markup
{span:class=shortcut}Project Settings→Version Control{span}
). By default, you will see project root directory only, but you can break your application down into smaller chunks, and place virtually every directory under its own version control system.

...

Your project might contain several sites, each one with its own set of files with the same names (

span
classcode
Wiki Markup
{span:class=code}init.py, models.py, tests.py, views.py{span}
). When they are opened in the editor, it's rather confusing... How can one tell which site they belong to? PyCharm helps make them stand out by painting their editor tabs (
span
classshortcut
Wiki Markup
{span:class=shortcut}Settings/Preferences→Project Settings→File Colors{span}
). Break down your project into smaller chunks - scopes (for example, a scope per site), and select a color for each one.

...

Remember, you’ve initially selected the look and feel for your IDE on the first start? If you are not happy with the result, now it’s time to change your mind. In the page

span
classshortcut
Wiki Markup
{span:class=shortcut}Settings/Preferences→Appearance and Behavior→Appearance{span}
you can select "look and feel" of your PyCharm installation. Just click the Look and feel drop-down, and select the scheme you like better. You don't need to close the Settings/Preferences dialog dialog to observe the results of your experiments: click Apply
span
classshortcut
Wiki Markup
{span:class=shortcut}Apply{span}
, see what happens, and close the dialog when you are quite happy with what you've got.

...

The whole bunch of pages under the Editor node (

span
classshortcut
Wiki Markup
{span:class=shortcut}Settings/Preferences→Editor{span}
) helps you tune every aspect of the editor's behavior. Note that PyCharm comes with the predefined color scheme, but if you want to make up something very personalized, you are welcome to do it: save the default scheme with a new name, and start changing its background, font, colors of syntactical elements, error highlighting etc., and immediately observe results in the preview pane.

...

The set of keyboard shortcuts you work with is one of your most intimate habits - your fingers "remember" certain combinations of keys, and changing this habit is rather painful. With this in mind, PyCharm supplies you with a wide range of pre-defined keymaps (

span
classshortcut
Wiki Markup
{span:class=shortcut}Settings/Preferences→Appearance and Behavior→Keymap{span}
), for those who prefer Eclipse, or for those who've had long experience with Visual Studio... You can create your very own keymap on the base of an existing one.

And finally, there is a magic shortcut

Ctrl + Back Quote
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl + Back Quote{span}
that helps you switch between schemes (all of them - keymaps, colors, code styles, and L&F) without the Settings dialog (for Windows and Linux users only).

...

  • At every stage of development, use code completion (
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Ctrl+Space{span}
    ), which takes into account the current context. For example, depending on the place where you invoke code completion, you can complete keywords or code blocks, infer types, or complete methods and properties.
    Refer to the tutorial Code completion and to the product documentation for details.
  • Use live templates/snippets (
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Ctrl+J{span}
    ) or surround templates (
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Ctrl+Alt+J{span}
    ) to produce entire code constructs. PyCharm comes with a wide range of ready-to-use live templates, or snippets, which you can explore in the Settings/Preferences dialog ( Editor → Live templates
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Editor → [Live templates|http://www.jetbrains.com/pycharm/webhelp/live-templates-2.html]{span}
    ).
    If you see that you are lacking something especially important for your development goals, extend this set of snippets with your own ones. Don't also miss the possibility to surround with complete code constructs (
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Ctrl+Alt+T{span}
    ). Refer to the tutorial Creating and applying live templates (code snippets) and to the product documentation for details.
  • Almost like a pair programmer, PyCharm keeps an eye on what you are currently doing, and comes up with smart suggestions, which are marked with a red or yellow light bulb sign. If you want to know exactly what is there under the light bulb, click it, or press
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Alt+Enter{span}
    . This way you can, for example, auto-create a new method that you are already using in the code, but have not yet declared.
    Refer to the tutorial Quick fixes and intention actions once more and product documentation for details.

...

However, you might want to look deeper into the code of your application. In this case, you have to inspect a whole project, or any of its parts (

Code→Inspect Code
span
classshortcut
Wiki Markup
{span:class=shortcut}Code→Inspect Code{span}
), and explore results in the Inspection tool window:

...

Let's start with finding fragments of text. One of the most basic means of navigation and search in the source code is our good old

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+F{span}
command: start typing your search string, and get immediately to its occurrences in the current file:

...

But PyCharm goes further, and helps you look for a certain string within a directory, or any arbitrary scope, or an entire project (

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+F{span}
):

Besides that, PyCharm suggests a more sophisticated approach, namely search for usages. For example, if you want to navigate from a symbol to one of its usages within your application, press

span
classshortcut
Wiki Markup
{span:class=shortcut}Alt+F7{span}
, or choose Find Usages
span
classshortcut
Wiki Markup
{span:class=shortcut}Find Usages{span}
on its context menu:

Actually, there are several commands that help you find out where a certain symbol is used: you can jump from one usage to another in the current file (

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+F7{span}
), view usages in the current file color-coded (
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+F7{span}
), or across a whole project in a popup list (
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Alt+F7{span}
).

If you want to jump from a symbol to its declaration, just middle-click its name, or press

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+B{span}
.

To quickly find an element by name and open it in the editor, use navigation pop-up: press

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+N{span}
(for a class),
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+N{span}
(for a file), or
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+Alt+N{span}
(for a symbol), and start typing the name you are looking for. The list of matching names shrinks as you type, but this is just one of the handy facilities: you can use the asterisk wildcard, all caps for CamelHumps, or spaces for snake_case names, slashes for nested folders and so on, and so forth.

...

Ways to navigate across the IDE are numerous, and we'll briefly outline just some of them. Let's start with the switcher: press

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Tab{span}
to show the switcher, which is a list of the PyCharm's tool windows and open files, and then, keeping the Ctrl
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl{span}
key pressed, use Tab
span
classshortcut
Wiki Markup
{span:class=shortcut}Tab{span}
or arrow keys to scroll to the component you want to go to:

...

If you select a file in one of the IDE components, and want to view it in another one (the editor, Project view, Navigation bar, or a changelist), then use Select Target (

span
classshortcut
Wiki Markup
{span:class=shortcut}Alt+F1{span}
):

And finally, don't forget that pressing

Esc
span
classshortcut
Wiki Markup
{span:class=shortcut}Esc{span}
will bring you back to the editor, wherever you are!

...

You don’t need the main menu to invoke an action - you can simply invoke it by name. Press

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+A{span}
, and type characters, which, to your opinion, should be present in an action name:

...

Note that you can search among the actions not included in the main menu - just press

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+A{span}
once more.

Anchor
everywhere
everywhere
Navigating and searching everywhere

PyCharm suggests a new way of navigation and search. Double press

Shift
span
classshortcut
Wiki Markup
{span:class=shortcut}Shift{span}
, or click in the right end of the main toolbar, and see the Search everywhere dialog. Using this approach, you can look for any item of the source code, databases, actions, elements of the user interface, etc. in a single action.

...

You can easily launch a Python script from its context menu, or with a handy shortcut

span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Shift+F10{span}
. However, if you want to use some other run/debug configuration, you have to choose one on the main menu, and then press
span
classshortcut
Wiki Markup
{span:class=shortcut}Shift+F10{span}
.

Refer to the tutorial Code running assistance, and to the product documentation Running.

...

PyCharm also helps those who love the full control of an interactive console: on the

Tools
span
classshortcut
Wiki Markup
{span:class=shortcut}Tools{span}
menu, you can find commands that launch the interactive Python or Django consoles. Here you can type commands and execute them immediately. Moreover, PyCharm's interactive consoles feature syntax highlighting, code completion, and allow scrolling through the history of commands (
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl+Up/Down{span}
).

PyCharm also makes it possible to run in console source code from the editor - just make your selection, and then press

span
classshortcut
Wiki Markup
{span:class=shortcut}Alt+Shift+I{span}
(Execute selection in console on the context menu of the selection). This feature is explored in detail in the tutorial REPL - running an interactive console. See also the product documentation Working with consoles.

...

Cannot live without command line? OK, PyCharm helps with that too. Choose

Tools→Open Terminal
span
classshortcut
Wiki Markup
{span:class=shortcut}Tools→Open Terminal{span}
on the main menu, and enjoy:

...

Launching the debugging session is quite as simple: either use the context menu of a specific script, or select a suitable run/debug configuration, and then press

span
classshortcut
Wiki Markup
{span:class=shortcut}Shift+F9{span}
.

And finally, a very convenient way to select run/debug configuration and immediately launch it is

span
classshortcut
Wiki Markup
{span:class=shortcut}Alt+Shift+F10{span}
/
span
classshortcut
Wiki Markup
{span:class=shortcut} Alt+Shift+F9{span}
.

Refer to the tutorials Debugger, Breakpoints, and Debug run, and to the product documentation Debugging.

...