How to Install Python3 on AWS EC2?
Last Updated :
04 Jan, 2025
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual computer on which we can perform all our tasks and we have the authority to configure, launch or even dissipate this virtual computer.
In this article, we will learn how to install Python on AWS EC2.
Prerequisite:
- AWS account.
- EC2 Instance.
- User with privileges to create Instance.
Installing Python on AWS EC2 :
Follow the below steps to install Python on AWS EC2:
Step 1: Create an AWS Elastic Cloud Compute Instance.
Step 2: Start the EC2 instance that you have created in Step 1.

Step 3: Connect to your EC2 Instance by clicking on Connect Button.

Step 4: A prompt will pop up after connecting.

Step 5: Check if Python is already installed or not on our AWS EC2.
python --version

Step 6: At first update, Ubuntu packages by using the following command.
sudo apt update

Step 7: If Python3 is not installed on your AWS EC2, then install Python3 using the following command.
sudo apt-get install python3.7

Step 8: Wait for the process to end.
Step 9: We have successfully installed Python3 on AWS EC2, to check if Python3 is successfully installed or not, verify using the following command.
python3 --version

In this way, we can Install Python3 on our EC2 instance using EC2 Instance Connect.
Let’s try to create a Python program on nano and then execute that python program on our EC2 instance:
Python
#example using python3
#gfg.py
print("Geeks for Geeks is the best website for a programmer")
OutputGeeks for Geeks is the best website for a programmer

Output
Note: If you also use a free tier account, make sure you delete all the resources you have used before logging out.
Setting up a virtual environment for Python on the EC2 instance:
This can be useful for isolating different Python projects and their dependencies, as well as for managing multiple versions of Python packages. To set up a virtual environment, you can use the virtualenv package, which can be installed using pip3 install virtualenv. Once virtualenv is installed, you can create a new virtual environment with a specific Python version by running the command virtualenv -p python3 envname, where envname is the name of your virtual environment. You can then activate the virtual environment using the command source envname/bin/activate. Within the virtual environment, you can install packages using pip3 install as usual, and they will be isolated from the global Python environment on the EC2 instance. When you are finished working in the virtual environment, you can deactivate it using the deactivate command.
Similar Reads
How to Install Python 2.8 on AWS EC2?
AWS or Amazon Web Services is one of the biggest cloud services providers with a variety of services such as on-demand computational services, databases, storage space, etc. EC2 or Elastic Compute Cloud is one of its services which acts as an on-demand computing service on the cloud platform. From a
4 min read
How to Install PHP on AWS EC2?
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
2 min read
How to Install R on AWS EC2?
R is widely used as a different programming language. There are several programming languages are present for different purposes. The C programming language is used to get basic knowledge in the programming field. Java programming language is used to get some deep knowledge of programming & its
7 min read
How to Install Go on AWS EC2?
EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual computer on which we can perform all our tasks and we have the authority to configure, launch or even dissipate this virtual computer.Go is an open-source,
2 min read
How to Install MySQL on AWS EC2?
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
2 min read
How to Install a Python Module?
A module is simply a file containing Python code. Functions, groups, and variables can all be described in a module. Runnable code can also be used in a module. What is a Python Module?A module can be imported by multiple programs for their application, hence a single code can be used by multiple pr
4 min read
How to Install Python-arrow on Linux?
Arrow is a Python library for performing tasks with date and time. It presents a sensible and human-friendly approach to creating, manipulating, formatting, and converting dates, times, and timestamps. Arrow allows easy creation of date and time instances with timezone awareness. So, in this article
1 min read
How to Install AWS CLI on Ubuntu?
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts. Here are the step-by-step instructions to install AWS CLI on UbuntuStep 1:
3 min read
How To Install Docker On AWS EC2 ?
You can use the following instructions to install Docker on an AWS EC2 instance. Note that depending on the Linux distribution your EC2 instance is running, there may be differences in certain commands or processes. What is Docker?Docker is an OS-level virtualization that provides tools for building
3 min read
How to Install Python on Linux
This guide explains how to install Python on Linux machines. Python has become an essential programming language for developers, data scientists, and system administrators. It's used for various applications, including web development, data science, automation, and machine learning. This comprehensi
15+ min read