# Introduction and installation of PyCharm IDE

As a programmer, you should be focused on the business logic and creating useful applications for your users. In doing that, [PyCharm](https://www.jetbrains.com/pycharm/) by [JetBrains](https://www.jetbrains.com/) saves you a lot of time by taking care of the routine and by making a number of other tasks such as debugging and visualization easy.

This article assumes that you’re familiar with Python development and already have some form of Python installed on your system. Python 3.6 will be used for this tutorial. Screenshots and demos provided are for macOS. Because PyCharm runs on all major platforms, you may see slightly different UI elements and may need to modify certain commands..

> ***Note**:*
>
> *PyCharm comes in three editions:*
>
> 1. [*PyCharm Edu*](https://www.jetbrains.com/pycharm-edu/) *is free and for educational purposes.*
> 2. [*PyCharm Community*](https://www.jetbrains.com/pycharm) *is free as well and intended for pure Python development.*
> 3. [*PyCharm Professional*](https://www.jetbrains.com/pycharm) *is paid, has everything the Community edition has and also is very well suited for Web and Scientific development with support for such frameworks as Django and Flask, Database and SQL, and scientific tools such as Jupyter.*
>
> *For more details on their differences, check out the* [*PyCharm Editions Comparison Matrix*](https://www.jetbrains.com/pycharm/features/editions_comparison_matrix.html) *by JetBrains. The company also has* [*special offers*](https://www.jetbrains.com/pycharm/buy/#edition=discounts) *for students, teachers, open source projects, and other cases.*

## Installing PyCharm <a href="#installing-pycharm" id="installing-pycharm"></a>

This article will use PyCharm Community Edition 2019.1 as it’s free and available on every major platform. Only the section about the professional features will use PyCharm Professional Edition 2019.1.

The recommended way of installing PyCharm is with the [JetBrains Toolbox App](https://www.jetbrains.com/toolbox/app/). With its help, you’ll be able to install different JetBrains products or several versions of the same product, update, rollback, and easily remove any tool when necessary. You’ll also be able to quickly open any project in the right IDE and version.

To install the Toolbox App, refer to the [documentation](https://www.jetbrains.com/help/pycharm/installation-guide.html#toolbox) by JetBrains. It will automatically give you the right instructions depending on your OS. In case it didn’t recognize your OS correctly, you can always find it from the drop down list on the top right section:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FuCutSZ6rFTkaDPMSyfhZ%2Fpycharm-jetbrains-os-list.webp?alt=media&#x26;token=7e3decfa-52ee-4e01-86bc-3a0ec03e7995" alt=""><figcaption><p>Install using the Toolbox App</p></figcaption></figure>

After installing, launch the app and accept the user agreement. Under the *Tools* tab, you’ll see a list of available products. Find PyCharm Community there and click *`Install`*:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FRKgKzVQjnTuCgpnHmrUT%2Fpycharm-toolbox-installed-pycharm.webp?alt=media&#x26;token=b5cdcbb1-33e6-47c2-be7d-afd21157147e" alt=""><figcaption><p>JetBrains ToolBox</p></figcaption></figure>

You have PyCharm available on your machine. If you don’t want to use the Toolbox app, then you can also do a [stand-alone installation of PyCharm](https://www.jetbrains.com/help/pycharm/installation-guide.html#standalone).

Launch PyCharm, and you’ll see the import settings popup:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FBAR0RFptmlhciF3Dicqz%2Fpycharm-import-settings-popup.webp?alt=media&#x26;token=5b97479a-ec1f-465b-b44e-daba9a31821f" alt=""><figcaption><p>Popup</p></figcaption></figure>

PyCharm will automatically detect that this is a fresh install and choose *Do not import settings* for you. Click *OK*, and PyCharm will ask you to select a keymap scheme. Leave the default and click *Next: UI Themes* on the bottom right:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FwBGkg0giPfoOpyJWa74a%2Fpycharm-keymap-scheme.webp?alt=media&#x26;token=90132dea-b72f-4659-b12a-b888a8398eea" alt=""><figcaption><p>Customize PyCharm</p></figcaption></figure>

PyCharm will then ask you to choose a dark theme called Darcula or a light theme. Choose whichever you prefer and click *Next: Launcher Script*:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2F4svuQCR6AXycmTEpkCgV%2Fpycharm-set-ui-theme.webp?alt=media&#x26;token=b10495bd-4f66-40f5-891c-ae16cd4cec84" alt=""><figcaption><p>Customize PyCharm</p></figcaption></figure>

I’ll be using the dark theme Darcula throughout this tutorial. You can find and install other themes as plugins, or you can also [import them](https://blog.codota.com/5-best-intellij-themes/).

On the next page, leave the defaults and click *Next: Featured plugins*. There, PyCharm will show you a list of plugins you may want to install because most users like to use them. Click *Start using `PyCharm`*, and now you are ready to write some code!

## Writing Code in PyCharm <a href="#writing-code-in-pycharm" id="writing-code-in-pycharm"></a>

In PyCharm, you do everything in the context of a **project**. Thus, the first thing you need to do is create one.

After installing and opening PyCharm, you are on the welcome screen. Click *Create New Project*, and you’ll see the *New Project* popup:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FGpMSh4huiVcDbZK5wRDy%2Fpycharm-new-project.webp?alt=media&#x26;token=94044df7-fefa-4d7f-8d32-c6fcd0b525c3" alt=""><figcaption><p>Create new project in PyCharm</p></figcaption></figure>

Specify the project location and expand the *Project Interpreter* drop down. Here, you have options to create a new project interpreter or reuse an existing one. Choose *New environment using*. Right next to it, you have a drop down list to select one of *Virtualenv*, *Pipenv*, or *Conda*, which are the tools that help to keep dependencies required by different projects separate by creating isolated Python environments for them.

You are free to select whichever you like, but *Virtualenv* is used for this tutorial. If you choose to, you can specify the environment location and choose the base interpreter from the list, which is a list of Python interpreters (such as Python2.7 and Python3.6) installed on your system. Usually, the defaults are fine. Then you have to select boxes to inherit global site-packages to your new environment and make it available to all other projects. Leave them unselected.

Click *Create* on the bottom right and you will see the new project created:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FkfDJmfSMeqftplHaCQYZ%2Fpycharm-project-created.webp?alt=media&#x26;token=42a7f524-25f7-41d6-b64d-c367907e64e4" alt=""><figcaption><p>Tip of the Day</p></figcaption></figure>

You will also see a small *Tip of the Day* popup where PyCharm gives you one trick to learn at each startup. Go ahead and close this popup.

It is now time to start a new Python program. Type `Cmd`+`N` if you are on Mac or `Alt`+`Ins` if you are on Windows or Linux. Then, choose *Python File*. You can also select *File → New* from the menu. Name the new file `guess_game.py` and click *OK*. You will see a PyCharm window similar to the following:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2F8TODeG9IVNLZYrYqIHao%2Fpycharm-new-file.7ea9902d73ea.png?alt=media&#x26;token=86a97a9b-611f-4c37-bffd-2484e0c5feb5" alt=""><figcaption><p>PyCharm</p></figcaption></figure>

For our test code, let’s quickly code up a simple guessing game in which the program chooses a number that the user has to guess. For every guess, the program will tell if the user’s guess was smaller or bigger than the secret number. The game ends when the user guesses the number. Here’s the code for the game:

```python
from random import randint

def play():
    random_int = randint(0, 100)

    while True:
        user_guess = int(input("What number did we guess (0-100)?"))

        if user_guess == random_int:
            print(f"You found the number ({random_int}). Congrats!")
            break

        if user_guess < random_int:
            print("Your number is less than the number we guessed.")
            continue

        if user_guess > random_int:
            print("Your number is more than the number we guessed.")
            continue


if __name__ == '__main__':
    play()
```

Type this code directly rather than copying and pasting. You’ll see something like this:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FmteVgphR7OLorH0cLIXO%2Ftyping-guess-game.fcaedeb8ece2.gif?alt=media&#x26;token=fc8db920-4f8b-40de-a7e2-ecf79aec1820" alt=""><figcaption><p>PyCharm IDE</p></figcaption></figure>

As you can see, PyCharm provides [Intelligent Coding Assistance](https://www.jetbrains.com/pycharm/features/coding_assistance.html) with code completion, code inspections, on-the-fly error highlighting, and quick-fix suggestions. In particular, note how when you typed `main` and then hit tab, PyCharm auto-completed the whole `main` clause for you.

Also note how, if you forget to type `if` before the condition, append `.if`, and then hit Tab, PyCharm fixes the `if` clause for you. The same is true with `True.while`. That’s [PyCharm’s Postfix completions](https://www.jetbrains.com/help/pycharm/settings-postfix-completion.html) working for you to help reduce backward caret jumps.

## Running Code in PyCharm <a href="#running-code-in-pycharm" id="running-code-in-pycharm"></a>

Now that you’ve coded up the game, it’s time for you to run it.

You have three ways of running this program:

1. Use the shortcut `Ctrl`+`Shift`+`R` on Mac or `Ctrl`+`Shift`+`F10` on Windows or Linux.
2. Right-click the background and choose *Run `guess_game`* from the menu.
3. Since this program has the `__main__` clause, you can click on the little green arrow to the left of the `__main__` clause and choose *Run `guess_game`* from there.

Use any one of the options above to run the program, and you’ll see the Run Tool pane appear at the bottom of the window, with your code output showing:

<figure><img src="https://847702634-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6i4tTDVzxDUhKzBX7GT3%2Fuploads%2FctPDQBLGpJYDJb7ihiKF%2Fpycharm-running-script.33fb830f45b4.gif?alt=media&#x26;token=800447d5-5ff8-4a14-9e5d-fa68f7d768a6" alt=""><figcaption><p>Run python code</p></figcaption></figure>

## Conclusion

PyCharm is one of best, if not the best, full-featured, dedicated, and versatile IDEs for Python development. It offers a ton of benefits, saving you a lot of time by helping you with routine tasks. Now you know how to be productive with it!

In this article, you learned about a lot, including:

* Installing PyCharm
* Writing code in PyCharm
* Running your code in PyCharm
