Quick Start Guide
In this section:
- Before you start
- Initial configuration
- Set defaults from the Welcome screen
- Work with projects
- Customize everything for your project!
- Background tasks
- Use macros
- Work with multiple files
- Find your way through
- Code with smart assistance
- Run and debug your application
- Test your application
- Develop remotely
- Data sources and SQL support
- Polyglot IDE
- That's about it!
Welcome to PyCharm! This short guide aims to help you get a grip on the IDE.
Before you start
Make sure that the following prerequisites are met:
- Python interpreter is downloaded and installed on your computer.
If not, follow these download and installation instructions.
PyCharm supports Python from version 2.4 up to the version 3.6.
- PyCharm is downloaded and 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.
PyCharm is cross-platform and works on Windows, Mac OS X, and Linux.
When you start PyCharm for the very first time, you are asked whether you have a previous version and what to do with the settings. For the purposes of this tutorial, assume that there is no previous version, and click OK:
Next, you get the PyCharm Licence Activation dialog, where you have to specify your particular license:
After you have specified your license, PyCharm shows the initial setup dialog. Here you have to select the keymap and themes of the IDE and editor you want to use. Click the down arrow (Click to show preview) to assess what your choice will look like:
Note that PyCharm has several pre-defined keymaps: for those who like Eclipse or Visual Studio, for Emacs fans, GNOME, KDE, and more. Explore the list of available keymaps in the Keymap page of Settings/Preferences dialog.
If later you decide that your initial choice of the keymap was wrong, you can always change your settings. To learn more about configuring the keymap, refer to the section Configuring Keyboard Shortcuts.
Set defaults from the Welcome screen
Again, if this is your very first start (or if you have no open project), you see the Welcome screen:
If you click Configure, PyCharm shows the drop-down list that suggests you to configure settings/preferences, plugins, import and export settings, and check for updates. Choose Settings/Preferences and see the Settings/Preferences dialog. Look at this dialog - it has the header Default Settings/Preferences.
What does it mean? These settings will be used every time you create a new project.
For example, you want all you newly created projects to use the same interpreter - OK, you can define such an interpreter in the Default Project settings:
Note that the interpreter settings relate to a default project.
The settings that pertain to a default project, are marked with the icon .
The Editor settings pertain to your working environment.
Suppose you want to use some particular color scheme for the editor, and you are not happy with the colors suggested by default. OK, select the base scheme, create a copy or it, and then change the colors (the schemes suggested by default are not editable).
It is also possible to set your preferred font size for the editor - this is done in the Font page under the Colors and Fonts node in the Settings/Preferences dialog. Again, you have to create a copy of the scheme first, if you haven't done it yet, and then specify the desired font size for the editor. This font size will apply to the current editor tabs and to all the newly opened editors. However, it does not affect the font size of the IDE components.
Note that you can always see the results of your experiments in the Preview pane:
Change Settings/Preferences later
For example, you want to change Look and Feel (theme) of the IDE. Note that PyCharm comes with several pre-defined themes. The set of available themes depends on your platform. You can find the theme of your choice in the Appearance page of the Settings/Preferences dialog.
This is how you can change the IDE theme:
- On the main toolbar, click , or press Ctrl+Alt+S.
- Expand the Appearance and Behavior node, and click Appearance.
- On the Appearance page, select the theme you prefer from the drop-down list
Note the link Reset that appears on top of the dialog box - if you've changed your mind, click it to roll the changes back. Also note the button Apply that becomes enabled when you hover your mouse pointer over it:
You can also change the other settings that define the look and feel of your PyCharm, for example, the windows' behavior.
- Apply the changes. You might be suggested to restart the IDE (for example, when you change theme to or from Darcula).
OK, the theme of PyCharm has been changed, but you are still not happy with the appearance of your code in the editor. For example, you want another highlighting color for the current line. Let's do it.
- Once more, on the main toolbar click to open the
expand the node Editor, and then click Colors and Fonts.
Note that you cannot change your pre-defined color scheme - you must create a copy of it first:
- Click the button Save As..., and type the name of your new color scheme:
This new color scheme is editable, and you can proceed with changing it to your taste.
- Under the Colors and Fonts node, click General, in the list of components, expand the Editor node, and locate the item Caret row.
- Click the background color snippet to open the color picker:
By the way, you have already noticed that some of the nodes are marked with . It means that the settings defined on these pages pertain to the current project. The pages without this icon contain settings that pertain to the entire working environment.
Difference between the L&F theme and the color scheme of the editor
Mind the difference between the IDE theme (look&feel) and the color scheme of the editor. The former relates to the entire IDE, while the latter relates to the editor only. It is quite possible to have a dark theme for the IDE (for example, Darcula), and one of the light color schemes for the editor (for example, Default). So doing, all the PyCharm components will be rendered in one color scheme, and the editor pane in the different one:
Work with projects
Everything you do in PyCharm, you do within the context of a project.
In PyCharm, a project is a directory that contains source code, and a nested directory with the name
.idea. The directory
.idea is the place where
PyCharm stores all the necessary information - it's not visible
in the Project view.
From the user's point of view, a project is just a directory that contains some Python code.
What is most interesting about PyCharm project management, is its ability to open multiple projects in one frame. When you create a new project (File | New Project), or open an existing one (File | Open), 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.
You can have as many projects opened in one window as required. So doing, the first project is considered the primary project. All the symbols of the added projects are visible from the primary project.
Refer to the section Creating and managing projects for details.
As an exercise, create a new empty project, where you can develop some pure Python code. This case is discussed in detail in the tutorial Creating and Running Your First Python Project .
By the way, PyCharm suggests creating projects of the various types: Python, Django, Flask, Pyramid, web2py, Twitter Bootstrap, HTML5 Boilerplate, etc. You can explore the available types yourself, when creating a new project:
As you can see, PyCharm supports all the major Python-based frameworks. For each of the supported project types, PyCharm creates the corresponding file and directory structure, and all the necessary artifacts.
Customize everything for your project!
Look at the main toolbar — there is a Settings button . Clicking this button opens the Settings/Preferences dialog box, where you can change your project structure, set up version control, and tweak your working environment to make the development process a real pleasure.
Some of the settings pertain to a particular project — for example, project interpreter, version control configuration, or file colors. They are marked . The others — like the Editor settings, keymaps, or live templates — pertain to your whole working environment, and thus can be configured even without an open project.
Python interpreter is vital — without it you will not be able to do anything...
PyCharm will warn you, if you manage to create a project without an interpreter:
In PyCharm, you can define several Python interpreters - they just comprise the list of interpreters, available on your machine. From among them, you can choose the one to be used in your project.
You need to tell PyCharm which Python interpreter you want to use since it can use a different interpreter for each project:
PyCharm will use this information for indexing.
You can use Python interpreters of the following types:
This is the most straightforward way of using an interpreter. You download a Python interpreter, install it on your machine, and then specify the Python executable... See Configuring Python SDK for details.
With PyCharm, you can use interpreters located remotely, for example, on a reliable server. So doing, PyCharm makes it possible to configure remote interpreters via SSH connection, via Docker or Vagrant box.
Refer to the section Configuring Remote Python Interpreters for details.
Why do we need it all? Suppose, you are working on one project that makes use of, say, Django 1.6, and at the same time support another project requiring Django 1.2. In such a case, you need something that keeps your environment safe and consistent - a tool that allows creating an isolated working copy of a Python interpreter. Learn how to create a virtual environment in the documentation.
Packages and paths
Regardless of the interpreter type, PyCharm helps install and update the necessary packages and paths. For example, when PyCharm automatically detects that some of the required packages are missing or outdated, it suggests you to install or upgrade them - shows a right-pointing arrow .
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. Then, in the Project Interpreters dialog, select the interpreter you want to view the paths for, click and then, in the list of interpreter paths, refresh :
Find details in the sections Installing, Uninstalling and Reloading Interpreter Paths and Installing, Uninstalling and Upgrading Packages.
Surely, you keep your sources under a version control, right? Git? SVN? Mercurial? With PyCharm, it's easy to set up, and again the IDE does a good job auto-detecting the VCS already used for existing projects.
But you can fine-tune — just click Version Control node in the Settings/Preferences dialog. By default, you will see the 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.
In the Settings/Preferences dialog, you can also define some behaviors that are common for all version control systems: confirmation on creating or deleting files, tasks performed in the background, ignoring unversioned files and more.
Refer to the sections under Version Control with PyCharm for details.
In addition to a traditional version control system, you can use local history. With Local History, PyCharm automatically tracks changes you make to the source code, results of refactoring, and state of the source code based on a set of predefined events (testing, deployment, commit or update). Local history is always enabled.
Your project might contain several sites, each one with its own set of files with the same names (init.py, models.py, tests.py, views.py) . When they are all 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 ().
Break down your project into smaller chunks — scopes (for example, a scope per site), and select a color for each one.
Refer to the page Configuring Scopes and File Colors for details.
IDE and Editor
Working in an IDE actually means living in it, and it is quite natural to make your haunted place pleasant for your eyes and comfortable for your fingers. That's why PyCharm makes it possible to choose a look and feel for the IDE and the editor, configure your preferred set of keyboard shortcuts (keymap), fine-tune the scrolling behavior, highlighting, and more.
All these settings are (again) configured in the Settings/Preferences dialog: click to open this dialog, and see the list of pages. Here are three pages that might be of interest for the starter: Appearance, Editor, and Keymap.
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 Appearance page (Settings/Preferences | Appearance&Behavior | Appearance) you can select a "look and feel" of your PyCharm installation. Just click the Look and feel drop-down, and select the scheme that suits you better. You don't need to close the Settings/Preferences dialog to observe the results of your experiments: click Apply, 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 of the Settings/Preferences dialog 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 the 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 (Keymap), 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.
Finally, there is the magic shortcut Ctrl+Back Quote 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).
Refer to the section Configuring Keyboard Shortcuts for details.
Though you can choose any keymap that corresponds to your preferred editor (Emacs, Vim, TextMate, etc.), you might still want to open files in your preferred editor. You can easily do it by configuring an external tool. For example, you might want to open a current file in Emacs as an external tool.
Sometimes, when a long task is in progress, PyCharm shows a Progress bar. You can bring such a task to the background, but still see how it goes on. Refer to page Working with Background Tasks for details.
It would be nice to have a chance to simplify your work with the editor. Using macros is just one of the possible ways. Refer to the product documentation for details.
Work with multiple files
As you might have noticed, PyCharm opens each file in a separate tab in the editor.
PyCharm provides a handy way to switch between the various tabs, allows pinning and unpinning each tab, placing editor tabs along any of the four borders of the window, splitting the editor tabs, and more.
Refer to the documentation section Managing Editor Tabs for details.
Find your way through
Now when you know how to start working with PyCharm, it’s time to look at its navigation features. They will help you not to get lost and will also increase your productivity.
Searching is for sure the most familiar and necessary option that is used for quick navigation. With PyCharm you can search for any class, file, action or even an IDE setting with only one action. Double-press Shift or click the magnifier glass icon in the upper-right corner of the PyCharm window:
Search for project elements
The essential tool for project elements overview is the Project tool window (). It shows your project as a tree of files and directories. To access it, click the tool windows bar icon or press Alt+1:
To quickly find an element by name and open it in the editor, use the navigation pop-up: press Ctrl+N (for a class), Ctrl+Shift+N (for a file), or Ctrl+Shift+Alt+N (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.
Search for code elements
The basic way to navigate and search your source code is Ctrl+F. Start typing your search string, and get to its occurrences in the current file:
The ultimate way to navigate around the current file is to use the File Structure View (Alt+7 or Ctrl+F12) and search through it:
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 Alt+F7, or choose on its context menu, and observe the results in the Find Tool Window:
Use "Go to" actions to navigate to a declaration (Ctrl+B), implementations (Ctrl+Alt+B), type declaration (Ctrl+Shift+B), or super method (Ctrl+U).
There are many ways to navigate across the IDE. You may not remember all the actions and menu commands the first time around, and that’s OK. Don't worry! Any time you need any IDE action, you can find it in (Ctrl+Shift+A) or use Search Everywhere. So, let’s briefly outline some of the main commands.
Let's start with the switcher: press Ctrl+Tab to show the switcher, which is a list of the PyCharm's tool windows and open files, and then, keeping the Ctrl key pressed, use Tab or arrow keys to scroll to the component you want to go to:
Press Ctrl+E to see the list of recent files. Press Ctrl+Shift+E to see the list of recently edited ones.
If you have several IDE windows opened, use the Ctrl+Alt+Open Bracket and Ctrl+Alt+Close Bracket shortcuts to switch between them.
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 (Alt+F1):
Finally, pressing Escape will bring you back to the editor, wherever you are. Ctrl+Shift+F12 will hide all tool windows and leave only the editor.
Code with smart assistance
PyCharm is famous for its smart code analysis features. Whatever you do to develop your source code, it is always at hand, helping you create error-free applications with no time wasted.
Edit and write code
At every stage of development, in any files, try to use code completion (Ctrl+Space), which takes into account the current context. Depending on where you invoke this action, you can complete keywords or code blocks, infer types, , and more:
PyCharm comes with a wide range of ready-to-use live templates, or snippets, which you can explore in the Live Templates page of the Settings/Preferences dialog. If you see that you are lacking something especially important for your development goals, extend this set of snippets with your own ones.
PyCharm helps you follow code style guides. All the new code is formatted automatically according to the code style settings (Settings/Preferences | Editor | Code Style). Nevertheless you may need to format some part of the code or apply changes made in code style settings. To do that, use (Ctrl+Alt+L).
Analyze your code
We, developers, spend only 20% of our time writing new code, but up to 80% improving the existing code. To help you avoid errors and correct them faster, PyCharm gives you numerous hints and prompts based on the best development practices.
First, as you type, you immediately have all syntactical errors underlined with a red wavy line. If you place the caret at an error location, you will see a brief description of the problem at the tooltip, and also in the left side of the Status Bar. Besides that, you see red stripes along the validation bar, or the marker bar. If you hover your mouse pointer over such a stripe, you see the error description at the tooltip.
As you type your code, PyCharm, like a diligent pair programmer, keeps a close eye on what you are currently doing. Moreover, the IDE comes up with smart suggestions, also called intention actions, which are marked with the or icons. Click such an icon, or press Alt+Enter to auto-create a new method that you have not yet declared, fix an if/else statement, and much more:
The next level is static code analysis, or code inspections: your code is analyzed without actually executing it. Actually, PyCharm inspects code in the current file on-the-fly, and shows inspection results in the marker bar as colored stripes. If you see that the right side of your IDE frame is bright with red stripes, beware — it means that your code contains serious errors. Less important things, recommendations to improve code, or warnings, are displayed as yellow stripes. Information for the current file is summarized in a colored indicator on top of the marker bar, which works as traffic lights: green means that everything is fine; at least one problem turns the indicator yellow or red.
Sometimes you need to look deeper into your code. In this case, you have to inspect a whole project, or any of its parts () and explore the results in the Inspection Tool Window:
PyCharm comes with a wide range of predefined inspections. All of them have a description and can be switched on or off, or configured as necessary in the Inspections page of the Settings/Preferences dialog:
To help you make your source code less tangled and more readable, PyCharm offers searching for duplicates in the whole project or its part (). Take a look at the detected repetitive fragments in the Duplicates tool window and decide what to do with them.
Create quality code
With PyCharm, it's quite easy to create a code of high quality — the IDE is a code quality tool itself. It integrates with PEP8, stands on guard of the code integrity and reports the code style violations.
Refer to the tutorial Code Quality Assistance Tips and Tricks, or How to make your code look pretty?
PyCharm makes it possible to view existing documentation for the symbols at caret. There are several possible ways to do it:
Refer to the product documentation Viewing reference information.
After inspecting your code, you may be interested in code refactorings provided by PyCharm. The IDE helps you rename safely, extract methods, superclasses and modules, introduce variables, constants, parameters, and more. Use (Ctrl+Shift+Alt+T) to view all refactorings available for the current code fragment.
Run and debug your application
While working with PyCharm, you'll come to a moment when you need to run or debug an application, a script, or a test. In all these cases, you need a special profile, or a run/debug configuration, which defines script name, working directory, environment variables, and other vital things.
You can easily launch a Python script from its context menu, or with a handy shortcut Ctrl+Shift+F10. However, if you want to use some other run/debug configuration, you have to choose one on the main menu, and then press Shift+F10.
Refer to the section Running for details.
PyCharm also helps those who love the full control of an interactive console: on the 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 viewing the history of commands (Ctrl+Alt+E or Up/Down arrows while in the editor).
See Working with Consoles for details.
Cannot live without command line? OK, PyCharm helps with that too. Click the Terminal tool window button, or press Alt+F12 and enjoy:
Oops... your application or script runs into a run-time error? To find out its origin, you will have to do some debugging. It starts with placing breakpoints (quite simple — just click the left gutter of the line where you want the breakpoint to appear), at which program execution will be suspended, so you can explore program data.
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 Shift+F9.
Refer to the section Debugging.
Test your application
It is a good idea to test your applications, and PyCharm helps doing it as simple as possible.
With PyCharm, you can:
- Create test classes
- Create special testing run/debug configurations
- Run and debug tests right from the IDE
- Explore results in the test runner window
PyCharm supports all the major Python testing frameworks:
For each of these frameworks, PyCharm provides its own run/debug configuration.
Besides the ability to use interpreters located remotely (which we have already discussed in the guide), you can also develop remotely.
First, with PyCharm, you can deploy your local applications to some remote server. To learn about deployment servers, refer to the section Configuring Synchronization with a Web Server.
Having deployed an application, you can run, debug and test it remotely. PyCharm also helps you compare local and remote folders, and synchronize local copy with that deployed on the server.
Data sources and SQL support
As you might have noticed already, creating projects of the various types (Django, for example) requires a data source. It is also quite possible that you inject SQL statements into your source code.
PyCharm does not enable you to create databases, but provides facilities to manage and query them. Once you are granted access to a certain database, you can configure one or more data sources within PyCharm that reflect the structure of the database and store the database access credentials. Based on this information, PyCharm establishes connection to the database and provides the ability to retrieve or change information contained therein.
See Databases and SQL for details.
That's about it!
Here we have given a very concise overview of some vital PyCharm facilities, just to give you a quick start. There are numerous important features that can help make your life easier and your source code nicer and cleaner.
Enjoy developing with PyCharm!