Return to site

Easy Python for beginner #2: Install Python and Setup the ideal environment

10-minute reading

In this tutorial, we will walk you through how to install Python to your computer, both Mac and Window.

If you already have Python installed for your computer, please skip to the final part of this article for the environment setup.

Remember that you might encounter lots of problems during the setup. When blockers come, don't forget to utilize these exclusive supports (eg. 1:1 Live QnA Session, Accountable Buddy Groups, etc) that we design to help your life easier!

Here is the cheatsheets of what we will cover in this tutorial

Install Python on Mac

For a Mac, Python usually comes pre-installed. To check if Python is pre-installed, let’s open up our terminal. Within our terminal, let’s type this line of code

python3 --version

And press enter.

If the result is Python 3.x, you are good to go! If the result is otherwise, you will need to go to the website python.org/downloads to download Python and install it as any other software.

After installing, let’s check again in the terminal. Don’t forget to close the previous terminal session, and open up a new terminal to make sure that the terminal is updated.

Let’s open up the Python package you just installed. You can see that the Python package provides you with a code editor called IDLE. You can use IDLE to code, but we highly recommend you to check the later part of the tutorial, where we walk you through how to set up a more proper environment.

Install Python on Window

First, let’s open up our command prompt. Within the command prompt, let’s type this line of code

python --version

And press enter.

If the result is Python 3 dot a number, you are good to go! If the result is otherwise, eg. Python 2, you will need to go to the website python.org/downloads to download Python and install it as any other software.

After installing, let’s check again in the command prompt. Don’t forget to close the previous session, and open up a new one to make sure that the command prompt is updated.

Let’s open up the Python package. You can see that the Python package provides you with a code editor called IDLE. You can use IDLE to code, but we highly recommend you to check the later part of the tutorial, where we walk you through how to set up a more proper environment.

Set up the environment with Visual Studio Code

1. Install Visual Studio Code

Throughout this series, we will install and code on an IDE, which is short for Integrated Development Environment. Integrated development environment is a software application, that provides comprehensive facilities to coders. Some facilities can be named as: code editor, automation tools, or debugger, etc

At the start, even though there is not much difference, between using a simple editor (like IDLE), or using an IDE to code, we highly recommend you to start using and get yourself familiar with production-level tool like IDE . Sooner or later, you will need to get your hands on an IDE, so why not start early, right?

There are many IDE out there, but we will use Visual Studio Code (or as known as VSC) for this course. We know as a beginner, you will be very confused with all these setups. But trust me, you will get used to it very soon, through practice.

So let’s go ahead and download VSC from the website: code.visualstudio.com/download

2. Create a Python file

After installing VSC, let’s open it, and create a python file. When you open a new file, notice that your file is not a Python file yet. In order to make it a Python file, we need to add the suffix .py to the file name, and save it to your working folder.

3. Run Python code on VSC using Terminal

To run the code, there are many ways. The most common way, is to run the code through your terminal. First, let’s open the terminal.

Next, you need to make sure that your terminal is in the correct directory. A correct directory should be where your python file is located.

Let’s do it by using the command cd, which is short for change directory. And add the path to the your directory. You can get the path by dragging and dropping the file to the terminal.

After having the terminal in the correct directory, let’s run the code using the command

python3 filename.py

And press Enter

Make sure you save the file (Command + S for Mac, or Ctrl + S for Window) before running the file. Otherwise, the terminal will run an empty file and return nothing.

4. Run Python code on VSC using AREPL (Recommended Option)

Although using terminal is the most common way to run code, it will take several steps to get there. At the start, we will have a lot of short peaces of code to run, so let’s see how we can save our time by reducing the steps down to just one step.

We will do it with an extension called AREPL.

Let’s open activity bar and install the extension. After installing, you will see this icon on the top right corner. Let’s press this button to open the extension, and see how we can run our Python code.

Let's write a line of code. By default, the code will be executed as you type. But this might be irritating sometimes. If you have not finished typing your code, and the code run as you type, the error message will appear, until you finish typing the code.

If you don’t want the code to be executed as you type. you can open the setting, scroll all the way down to the bottom, change the setting from default to “onSave”. Now, the code will only executed when you save the file.

Ideal screen Setup

Last off, we highly recommend you to arrange your computer screen like this.

Through many studies on effective learning, we learn that the best way to learn to code, is to code as you learn. So you keep one side of the screen to watch the video, and another side to practice coding right on the spot.

That’s mainly it. By now, you should already have the best settings to start your Python journey.

If you find it difficult to learn and apply Python to real-world problems, or hard keep yourself accountable to make consistent progress? 

Check out our exclusive supports for Python learners

All Posts
×

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!

OK