DEV Community

Cover image for Python Installation
Introschool
Introschool

Posted on

Python Installation

How to install Python?

To start working with the Python, first, you have to install it. You can install Python from the download section of Python’s official website. In this course, we will use the Python3 version. Let’s start the installation process.

Install Python in Windows

Follow the below steps to install Python on Windows system.

  • Go to the windows download link at Python.org.
  • Underneath the heading Python Releases for Windows click on the Latest Python 3 Release - Python 3.x.x. Here x denotes the latest version.
  • Go to the Files section and select either Windows x86-64 executable installer for 64-bit or Windows x86 executable installer for 32-bit and download it.
  • After downloading it, run the installer.

Install Python in Linux

It's very likely that Python is already installed in the Linux system. To check that the Python is installed or not, open the console and type the following command.

$ python --version
Enter fullscreen mode Exit fullscreen mode

This will show you the Python version that is installed in your system.
If you don't have Python installed, or if you want a newer version, you can install it as follows:

$ sudo apt install python3
Enter fullscreen mode Exit fullscreen mode

Install Python in Mac

Follow the below steps to install Python on Mac OS.

  • Go to the Mac download link at Python.org
  • Underneath the heading Python Releases for Mac OS X click on the Latest Python 3 Release - Python 3.x.x. Here x denotes the latest version
  • Go to the Files section and select macOS 64-bit/32-bit installer and download it.
  • After downloading it. Run the installer.

Python IDLE

After getting done with the installing part, You can search for the Python IDLE in your system. IDLE stands for Integrated DeveLopment Environment. Think of it as a workspace for Python programming. It comes with the Python Interactive shell and file editor.

Python Interactive Shell

When you start IDLE, a window with an interactive Python shell pops up. You can directly write code in this and see the output immediately.
You will see this symbol ‘>>>’, It is called prompt. You can write a complete code fragment and after pressing enter, Python interpreter will execute it.

>>> print('Hello World')
Hello World
>>> 2 +2
4
>>> import math
>>> math.sqrt(25)
5
Enter fullscreen mode Exit fullscreen mode

File Editor

When we do programming, we mostly write code in the files. The Python files ended with .py extension. So file editor is used for creating new files or editing existing files. You can run those files in IDLE itself and see the output or error.

How to Work with Command Line?

Working with the command line is an essential part of the programming. In this section, we will see some basic commands that are frequently used. We will also see how you can run a Python file from the command line.

Basic Commands

To understand these commands let’s make file structure and then we will run below commands and see the result.

head_folder
  - first_folder
      - code.py
Second_folder
      - hello.py
Enter fullscreen mode Exit fullscreen mode

You can see the above file structure. Here parent folder has two folders and those two folders have one-one Python file.
You can access the particular file only if you are in the same folder as the file.

cd

To change the directory this command is used.

Home: $ cd head_folder/first_folder

Now you are in first_folder
Home:~/head_folder/first_folder $

Enter fullscreen mode Exit fullscreen mode

cd ..

To come one folder above use this command.

 Home: $ cd head_folder/first_folder

Now you are in first_folder
Home:~/head_folder/first_folder$ cd ..

Home:~/head_folder$

Enter fullscreen mode Exit fullscreen mode

ls

This command list all the folders and files in that particular folder.

  Home: $ cd head_folder/first_folder

Now you are in first_folder
Home:~/head_folder/first_folder$ cd ..

Home:~/head_folder$ ls
first_folder second_folder

Enter fullscreen mode Exit fullscreen mode

Run Python File from Command Line

To run the Python file first you have to be in the folder the file is present. Suppose you want to run hello.py file then see the below commands.

 Home: $ cd head_folder/first_folder

Now you are in second_folder
Home:~/head_folder/second_folder $ python3 hello.py
Enter fullscreen mode Exit fullscreen mode

The command python3 hello.py will run the file and execute the code inside the file.

Text Editors

We know that you can work in IDLE but text editors make your programming experience much better. They make your code looks beautiful and neat. They highlight the code syntax for better readability and lots of other features come with text editors.

Here is the list of text editors that you can use for programming.

  1. Notepad++
  2. Sublime
  3. Visual Studio Code
  4. Atom

You are free to choose any one of them but we will suggest you install the Sublime text editor. Because it is very light and easy to use.

Top comments (0)