PyCharm: An Animated Guide to Creating Projects and Setting their Behavior
I am a visual learner. I learn quickly and remember longer if you show me how to do something with a visual animation rather than with text. Enclosed, you find visual animations of PyCharm for creating a new project and setting up a project related coding lifecycle tools.
Note: The April. 2020 release of PyCharm Professional now supports Jupyter. I show Jupyter in a virtual environment (Docker image).
Note: I am on a Macintosh. It may be different on Windows or Linux. Also, I use PyCharm Professional. The free version will not have some of the features shown.
Warning: The following is my perception and the reason for creating an Animated Guide for Pycharm.
I do often find that JetBrain’s documentation on Pycharm is, in some cases, misleading or not clear.
In my opinion, this is because of:
- PyCharm is on much different hardware and operating system platforms;
- There is a constant flow of new features regularly added;
- It is both wordy and hard to describe an action that requires multiple keystrokes and/or numerous mouse-clicks.
- It is tough to describe any steps that require actions outside the Pycharm IDE.
The why, the motivation for your command selection in PyCharm is dependent on your approach, strategy, and tactics. I focus on what you need to do to perform these everyday actions in PyCharm:
- Creating projects;
- Setting project behavior.
Note: In no way am I trying to replace JetBrain’s documentation on Pycharm. I focus on a small subset of Pycharm’sextensive command set that I often use for creating a new project and setting up a project related coding lifecycle tools.
Some of these animations may not appear in your Medium app on your iPhone or iPad device. Android may have the same problem. If you forward this article to Safari or Chrome, there is no problem. I suspect it has to do with the HTML5 <animate tag> and memory limitations. -author
Create a project from the local file system
PyCharm Help Text: https://www.jetbrains.com/help/pycharm/creating-empty-project.html
To create a project, do one of the following:
From the main menu, choose File | New Project
On the Welcome screen, click Create New Project
New Project dialog opens.
… 5+ more steps
The animation shows adding the new project Photonai from a local directory in PyCharm.
Create a project from a Github Repo
If your objective is to contribute to a project hosted on GitHub, the recommended method is to
git clone <GitHub-project-URL> into a local directory.
You can clone a repository that you want to contribute directly from PyCharm and create a new project based on it. (ed: 10+ step process)
I create a project in Pycharm by cloning the open-source package Rope hosted on GitHub.
Note: Depending on your network speed (mine is 100 Mb/sec). The complete download from the GitHub repo may take greater or less than 60 seconds.
Configure a virtual environment (Docker) as the Python interpreter for a project
I put the Jupyter IDE and some extensions placed in a Docker image as documented in:
Adding Jupyter Notebook Extensions to a Docker Image
The Docker image for our Jupyter Python and R users required them to set their Nbextensions preferences after every…
PyCharm Help Text:: https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
In the Settings/Preferences dialog ⌃⌥S, select Project <project name> | Project Interpreter.
I show how to configure the PyCharm virtual environment to be a Docker (enhanced with Jupyter) image.
Setting Project Behaviors
Configure Jupyter for a project
I live in PyCharm the majority of the day, when collaborating on a geographically distributed open-source project, production coding, developing and running test suites, or version control with GitHub.
By enabling Jupyter to work inside Docker inside PyCharm, I get all three environments in one, the PyCharm environment.
PyCharm Help Text: https://www.jetbrains.com/help/pycharm/jupyter-notebook-support.html
Notebook support in PyCharm includes:
Editing and preview:
Live preview of the cell execution output and Markdown content.
Auto-saving changes that you make in your files. Saving is triggered by various events, for example, closing a file or a project, or quitting the IDE.
Error and syntax highlighting.
Ability to run cells and preview execution results.
Dedicated Jupyter Notebook Debugger.
Shortcuts for basic operations with Jupyter notebooks.
Ability to recognize .ipynb files and mark them with the
To configure Jupyter for PyCharm is a two-step process:
- Place Jupyter in your environment which is shown by the animation above, “Configure Jupyter for a project”;
- Then I configure PyCharm Project Jupyter Server to the URL of the Dockerized Jupyter link. Note Jupyter is served out of
8888is kept free.
Note: Each time you boot, you must launch the Docker image, docker-compose up, in your local Docker directory. Ex:
Note: Each time you build a new docker image. docker-compose build, in your local Docker directory. Ex:
˜/PROJECTS/photon/photonai/docker/dev/ you must configure Jupyter for PyCharm, as shown in the following animation.
If you don’t, then you reference Jupyter on port
8889 using an old token that is no longer accepted.
Show Documentation on Mouse Move
I can show the docstring of any method or function while in PyCharm to see the correct signature and types of the arguments. From there, I often
Show Source, which takes me directly to the file and source code in that file of a project.
PyCharm Help Text: https://www.jetbrains.com/help/pycharm/viewing-reference-information.html
In the Settings/Preferences dialog ⌃⌥S, go to Editor | Code Editing | Quick Documentation and check the Show quick documentation on mouse move checkbox.
The following shows the signature and docstring (if it exists) of the function, method or class when you hover your mouse.
Note: You can choose among 4 options by clicking on vertical ellipses in the far right of the documentation pop-up. One of these options is to turn off
I install the
Materials Design UI. , which shows a new graphic layout style. Notice, on the far left display of the project Photonai directory, the display of some of the file icons changed.
PyCharm Help Text: https://www.jetbrains.com/help/pycharm/managing-plugins.html
Most plugins can be used with any JetBrains product. Some are limited only to commercial products. There are also plugins that require a separate license.
If a plugin depends on some other plugin, PyCharm will notify you about the dependencies. If your project depends on certain plugins, add them to the list of required plugins.
By default, PyCharm includes a number of bundled plugins. You can disable bundled plugins, but they cannot be removed. You can install additional plugins from the plugin repository or from a local archive file (ZIP or JAR).
Note: you can left-click on a plugin title to view its documention.
Note: After installing or uninstalling plugins, you must restart PyCharm.
Choosing a Testing Framework
The PyCharm default test framework is
Unittests. In the animation, I set the test framework to
PyCharm Help Text: https://www.jetbrains.com/help/pycharm/choosing-your-testing-framework.html
1. Open the Settings/Preferences dialog (press ⌃⌥S), and under the node Tools, click the page Python Integrated Tools.
2. On this page, click the Default Test Runner field.
3. choose the desired test runner:
Configuring Documentation Style for a Project
PyCharm presents a list of five supported styles. I use the Numpy Style for docstrings because it is suited for detailed documentation of classes, methods, functions, and parameters.
You can switch docstring style in Settings | Tools | Python Integrated Tools | Docstring format
I set the docstring style to
Configuring Snippets to Line-of-Code Completions for a Project
Kite integrates with PyCharm for an upgraded (IMHO) autocomplete experience while coding in Python. You may agree it improves the look of PyCharm's display of project directory layout.
PyCharm Help Text: https://kite.com/integrations/intellij/
Note: The left hand display changes:
- The vertical spacing is 1.5 lines (was 1.0 lines) between each directory name and each file names;
- There are now file type logos on each file name. Nice!
Adding External Tools : Formatting using Black
PyCharm can run an external tool for formatting. I use black, which formats a
.py file or the entire project into PEP-8 compliant format. The result is that all files are formatted the same. The follow-on result increases Readability.
PyCharm Help Text: https://www.jetbrains.com/help/pycharm/configuring-third-party-tools.html
You can define standalone third-party applications as external tools and run them from PyCharm.
You can pass contextual information from your project to the external tool as command-line arguments (for example, the currently selected or open file, the project source path, and so on), view the output produced by the tool, configure to launch the tool before a run/debug configuration, and more.
The following animation shows the use of a PyCharm external tool. Black formats all the files to the PEP-8 standard in the project Photonai.
Readability is one of the main goals of Python. PEP-8 is the standard to promote Readability by following a standard of format style. Black fully automates formatting so that developer is relieved of a mundane task.
There are visual learners, like myself, who prefer a visual animation rather than with text. I have provided some visual animations of PyCharm for that I accomplish for creating a new project and setting up a project related coding lifecycle tools.
I find these collected animations in one article, to be useful for me in my work in PyCharm.
In the future, I hope to author more visual animations of PyCharm and other tools. Let me know if this was helpful and what other tool visual animations you would like to see.