Installation
Linux and MacOS
On Linux and MacOS systems, Python should already be installed.
You can verify this using the method in the 'Checking installation' chapter.
If installed, you can skip to the 'Project setup' chapter.
Installing on Linux
If not installed, simply use your package manager to install 'python3'.
Arch
On Arch-based distros (e.g. Manjaro), run the following command:
sudo pacman -Sy python3
Debian
On Debian-based distros (such as Ubuntu), type:
sudo apt install python3
Installing on Windows
On Windows, navigate to the Python website (python.org) and install the latest stable build.
Scroll to the bottom of this page and find 'Windows installer (64-bit)'.
Open the .exe file and go through the installation process.
Note: Make sure to 'add Python to system PATH'. This allows us to use Python through the terminal.
Checking installation
Terminal setup
Once you have installed Python, open a system terminal.
On Linux and MacOS, this is called the 'terminal'.
On Windows, this is called the 'command prompt' or 'powershell'.
Checking Python version
Now we need to run a command to check if Python is installed.
The result should be the name of the Python version you installed, printed to the screen.
Linux or MacOS
On Linux or MacOS, type the following command to check if Python is installed:
python3 --version
Windows
On Windows, type this command into the command prompt:
py --version
Checking Python install
If this returns a Python version, such as below, you have successfully installed Python:
> python3 --version Python 3.11.3
However, if this returns an error, like below, try reinstalling Python:
> python3 --version zsh: command not found: python3
Project setup
In this chapter, we will set up the project structure, and the files we will be using.
Creating a folder
Firstly, create a new folder for the project.
In this course, we will create the 'learnpython' folder in the '/home/yourname/coding' folder.
You can create this folder through a file manager, or through the terminal.
Linux or MacOS command line
On Unix (Linux or MacOS), type the following commands.
First, navigate to your documents folder:
cd ~/Documents
If you haven't already, create a coding folder for all your projects:
mkdir coding
Finally, create our project folder:
mkdir learnpython
Windows command line
On Windows, first navigate to the parent directory:
cd C:/Users/yourname/Documents
If you don't already have one, create a programming folder:
md coding
Finally, create the 'learnpython' folder:
md learnpython
Creating a Python file
Now we need to create a Python file.
There are a few ways to do this, such as:
- Using a text editor
- Using the command line
Text editor
To create a new Python file, open a text editor, such as VS Code, and save the file.
Save the file with the '.py' extension.
For example, the file could be called 'hello.py'.
Save this file in your 'learnpython' directory.
Command line
You can also use the command line to create a Python file.
If you are not still in your project folder, navigate to it using the 'cd' command.
Then type the following:
. > hello.py
Replacing hello with the name of your file you want to create.
Python course
This lesson is part of the Python course.