Getting started with PyCharm

Marius Safta
Cluj School of AI
Published in
5 min readApr 2, 2019

Hello World,

In the previous two posts of this absolute beginner series, we installed Anaconda Navigator and learned about virtual environments. Having completed the basic setup, it’s now time to choose an IDE and get to coding.

I should mention from the start that choosing and IDE is not crucial when starting learning. Just go with anything that is comfortable for you… Any recommendations in this post are my preferences which might not match yours. That is absolutely fine, all is subjective :)

PyCharm Installation and Setup

PyCharm is developed by JetBrains which produces IDE applications for many popular languages (Javascript, C/C++, PHP, Ruby etc.). I’ve worked with PHPStorm for several years before starting with Python, so my transition to PyCharm was quite smooth.

PyCharm is available for download on Windows, Mac and Linux. The Professional Edition trial is 30 days, but, unlike other of their IDEs, JetBrains offers a perpetually free Community Edition.

Download and installation is a straightforward process. When launching PyCharm for the first time, you’ll have to go through a couple of settings. Choose a dark or light theme (I chose the dark side if anyone wonders 😄 ) and skip installation of other plugins for now. As a side note, you might notice that one of the plugins is for supporting the R language which was mentioned as an alternative to Python.

After setup is complete, you’ll see the welcome screen. It’s time to create our first project in PyCharm.

Creating a Project

On the Welcome screen, simply click Create a Project.

PyCharm Welcome screen

I’ve named the project learning_project. It will have its own folder on the disk. I’ve left the default path, but you can place the project wherever you wish.

New Project window

Expanding Project Interpreter: New Virtualenv environment we can see more details about the project.

Most important, PyCharm will create a new virtual environment for this project. This is done for all new projects, without any additional settings having to be made. Quite handy…

Then we see the base interpreter is the python we installed with Anaconda. So PyCharm recognizes any existing Python installations.

The other 2 checkbox options are more advanced, so there’s no need to worry about them for now.

Creating a Python file and running it

On the left side of the UI we see the Project. Right click on its name and create a new Python file.

Creating a new Python file .py

In the Python file add the same code from the numpy test in the previous post:

import numpy as np
a = np.array([1,2,3])
print(a)

To run the file, press CTRL+SHIFT+F10 (or just SHIFT+F10, depending on version). You’ll see the following error: No module named ‘numpy’

Oh, no! An error…

Do you have any idea what the problem is?

Well, we haven’t installed numpy inside this project’s virtual environment.

Installing a Package in PyCharm

Packages in PyCharm can be installed using pip, the package installation manager for Python.

In the lowest bar of the UI, click on terminal and type

pip install numpy
Installing numpy with pip

pip will then download and install the package inside the virtual environment. Any dependencies will automatically be collected and installed as well.

When the installation is successfully complete, you should see the following:

Installation is completed successfully

Running the file again will prove successful this time, with the expected value [1, 2, 3] being displayed on the screen.

Having a virtual environment automatically created for every project is just one of PyCharm’s features. The Getting started guide on the official site provides more thorough introduction.

Alternatives to PyCharm

There are of course many alternatives to PyCharm, which proves Python is a very popular language. Two are available inside Anaconda Navigator: Spyder and Visual Studio Code.

Spyder

Spyder is a Python IDE aimed specifically at Data Scientists. You can check out a great overview video here.

Visual Studio Code

A lightweight free code editor from Microsoft, Visual Studio Code is available on all platforms. It’s not set up for Python out of the box, but it has official Python support via an extension. Check out the get started guide.

Atom

Like Visual Studio Code, Atom is a light editor, not specific to Python, but highly configurable and offering Python support via extensions.

If you want to read more, here is a great overview of IDEs and code editors for Python: https://realpython.com/python-ides-code-editors-guide/

Conclusion

You can check them all out before deciding which one to use. My advice is not to dwell too much on this now, any option is good enough to start learning about Python, Machine Learning or Data Science… and you can always switch IDEs when you are more experienced.

Next post will be an overview of Jupyter Notebooks, an indispensable tool for any Python user.

Your opinions, feedback or (constructive) criticism are welcomed in discussions below or at @mariussafta

Join our Facebook and Meetup groups and keep an eye out for discussions and future meetups.

--

--