PyCharm Tutorial: Getting Started with PyCharm

PyCharm, created by the Czech company JetBrains, is a popular Integrated Development Environment (IDE) used in programming, particularly for the Python programming language. It is written in Java and Python, and its initial release was in February of 2010. PyCharm works with Windows, macOS, and Linux versions.

Upon installing PyCharm in your computer, you may also wish to refer to our tutorial on python for beginners.

It provides a graphical debugger, an integrated unit tester, coding assistance, support for web development with Django, and integration with Anaconda’s data science platform.

This PyCharm installation tutorial will help you learn how to create new projects, add files to projects, customize the UI, run and debug Python code, and explore a lot of other features.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

How to Install Numpy in PyCharm

You can download PyCharm from the JetBrains website.

Pycharm

Once you click on download, it will give you two options: Professional or Community. The professional edition of PyCharm requires a subscription, while the community edition is free.

download-pycharm

For this PyCharm tutorial, we will use the community edition. This will start downloading the .exe file. After the download is complete, run the file to install PyCharm.

open-file

edition-setup

Click on Finish to complete the PyCharm Community edition setup. 

Learn From The Best Mentors in the Industry!

Automation Testing Masters ProgramExplore Program
Learn From The Best Mentors in the Industry!

completing-edition-setup

Now that the installation is complete, let us discuss the PyCharm UI in this PyCharm tutorial. In the PyCharm UI, your options include File, Edit, View, Navigate, Code, Tools, VCS, Window, and Help.

pycharm-ui

If you want to make changes to the environment and the interface, click on File and go to Settings.

clickonfile

settings

Now, to write your Python script, go to File and select New Scratch File.

new-scratch-file

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

How to Create a Project in PyCharm?

Next in this PyCharm tutorial, let's create a new project by going to File and selecting New Project. Choose a name for the project and select create. You will see a pop-up asking how you want to open the project. I’ll choose This Window.

open-project 

It will take a while to create a virtual environment. Once it’s ready, start by naming your project, and then, right-click it, go to New and select Python file. Name the Python file you have created. In our example, we’ve named it PyCharm.

pycharm-tutorial-1

pycharmtutorial-2

At the bottom of the PyCharm window, you will find the Python Console, Terminal, and TODO options.

Let us continue this PyCharm tutorial performing some basic mathematical operations by importing the math module. It uses a full function (abs) to return the total value of a number.

math

You can see the Add Configuration option has changed to the name of the Python file. Next, click the green run button to execute your code. The Add Configuration will be reset every time you create a new project. There is a Run tab that comes up once your code executes successfully to display the output.

In the Python console, you can run one line of code, which will generate output beneath it.

python-console

PyCharm has a Refractor option, which allows you to rename a variable throughout the code. To do this, select the variable name, right-click and choose Refractor, and then click Rename.

refractor

How to Import NumPy in PyCharm?

In the next section of this PyCharm tutorial, we will cover how to import the NumPy module in PyCharm. However, if we use the following lines of code to import NumPy, it will throw an error.

numpy

To install NumPy on PyCharm, click on File and go to the Settings. Under Settings, choose your Python project and select Python Interpreter. Then, search for the NumPy package and click Install Package.

appearance-and-behavior

available-packages

Prepare Yourself to Answer All Questions!

Automation Testing Masters ProgramExplore Program
Prepare Yourself to Answer All Questions!

Now, let's rerun the code, and you can see this time that it executed successfully.

run-the-code

You can close your project by going to the File menu and selecting the Close Project.

If you want to open any file in PyCharm, select Open from the File menu and browse to the correct one. It will ask, “How would you like to open the project?”.  Select the method that works for you. 

You can edit the configuration of a project by selecting the name of the file and clicking on Edit Configurations.

/edit-configurations

This allows you to edit the Environment variables, choose the type of Python interpreter you need, select the Working directory, and so on.

working-directory

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

PyCharm offers multiple ways to run the code:

  1. Click on the Run tab on the menu bar.
  2. Select the green run button.
  3. Hit Shift+F10.
  4. Right-click and select Run.

You can select each line of code, and it will show a red-colored point, which refers to the breakpoint.

breakpoint

To debug a program, select the bug option present on the top right or click on Run from the menu bar and choose Debug. It will execute until the breakpoint, which can be continued until completion by pressing F8.

debug

Below is a small script that can help you understand more about how PyCharm works. Once you run this program, it will prompt you for inputs in the console.

st = input(“Enter X and Y”)

X, Y=[int(x) for x in st.split(‘,’)]

throw-an-error

If you try to give anything other than integer as inputs, it will throw an error.

console

Become an Automation Test Engineer in 11 Months!

Automation Testing Masters ProgramExplore Program
Become an Automation Test Engineer in 11 Months!

Let’s create a list and see how it works:

st = input(“Enter X and Y”)

X, Y=[int(x) for x in st.split(‘,’)]

lst = [[0 for col in range(Y)] for row in range(X)]

print(lst)

how-it-works

It results in a nested list with four zeros in each list.

Let's look at another example to see how you can loop through a list:

st = input(“Enter X and Y”)

X, Y=[int(x) for x in st.split(‘,’)]

lst = [[0 for col in range(Y)] for row in range(X)]

for row in range(X):
      for col in range(Y):

      lst[row][col] = row*col

for row in range(X):
     print(lst) 

loop through

The following code will print the elements in a list horizontally:

st = input(“Enter X and Y”)

X, Y=[int(x) for x in st.split(‘,’)]

lst = [[0 for col in range(Y)] for row in range(X)]

for row in range(X):
    for col in range(Y):

        lst[row][col] = row*col

for row in range(X):
   for col in range(Y):
        print(lst[row][col])

following-code

The code below allows users to print each row with one underneath the other.

st = input(“Enter X and Y”)

X, Y=[int(x) for x in st.split(‘,’)]

lst = [[0 for col in range(Y)] for row in range(X)]

for row in range(X):
    for col in range(Y):

        lst[row][col] = row*col

for row in range(X):
       print(lst[row])

underneath-row

Python has wonderful data visualization libraries, such as Matplotlib, that help you build interactive graphs and charts. Go to Settings and in Python Interpreter, search for Matplotlib, and click on Install Package.

Here is a simple straight-line graph plotted using Matplotlib:

import matplotlib.pyplot as plt

plt.plot([1,2,3,4],[1,2,3,4])

plt.show() 

matplotlib

In the last section of this PyCharm tutorial, we will learn how to import a .csv file onto PyCharm using Pandas.

Learn data operations in Python, strings, conditional statements, error handling, and the commonly used Python web framework Django with the Python Training course.

How to import a .csv file onto PyCharm using Pandas?

Pandas is a widely popular library used for data analysis and manipulation in Python. You need to import the pandas package to use it. To do so, go to File menu >> Settings >> Python Interpreter >> Search for pandas >> install package.

The program below will help you import a CSV file onto PyCharm and store it as a data frame using the pandas library.

import pandas as pd

path = “D:/cars.csv”

df = pd.read_csv(path)

print(df)

import-pandas

If you want to see the first five records of the data frame, use the head() function.

dataframe

With that we have come to the end of the Pycharm installation guide.

Conclusion

We hope this article helped you understand how to work with the Python language using the PyCharm IDE. You would've learned how to download and set up the PyCharm IDE, create a project and Python file, configure the settings, write simple code in Python, and run it in various ways. You got an idea of how to install packages, such as NumPy, Matplotlib, and pandas. Finally, you imported a .csv file onto PyCharm using pandas. That’s just some basics. If you want to learn more complex Python coding, enroll in our PGP Full Stack Development Courses today! Hope you liked the article, in case of any doubts leave your questions below.

About the Author

Avijeet BiswalAvijeet Biswal

Avijeet is a Senior Research Analyst at Simplilearn. Passionate about Data Analytics, Machine Learning, and Deep Learning, Avijeet is also interested in politics, cricket, and football.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.