Toggle search
Search
Toggle menu
notifications
Toggle personal menu
Editing
Installing Python
From OpenCourse
Views
Read
Edit
Edit source
View history
associated-pages
Page
Discussion
More actions
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== 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'''<nowiki/>' chapter. If installed, you can skip to the ''''Project setup'''<nowiki/>' 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 [https://python.org/download/windows 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'''<nowiki/>'. On Windows, this is called the ''''command prompt'''<nowiki/>' or ''''powershell'''<nowiki/>'. === 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'''<nowiki/>' folder in the ''''/home/''yourname''/coding'''<nowiki/>' 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'''<nowiki/>' 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'''<nowiki/>' extension. For example, the file could be called ''''hello.py'''<nowiki/>'. Save this file in your ''''learnpython'''<nowiki/>' 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'''<nowiki/>' 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. [[Python Hello World|Go to the next lesson]]. [[Intro to Python|Go to the previous lesson]]. [[Python|Go back to the course overview]]. [[Category:Python]] __FORCETOC__
Summary:
Please note that all contributions to OpenCourse are considered to be released under the Public Domain (see
OpenCourse:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)