Installing Python 3.12 on AWS EC2 Instances
You’ve set up your AWS EC2 instance and are ready to install Python, only to find that running the usual sudo yum install python3
command doesn’t yield the expected results. If you’re trying to leverage Python’s powerful capabilities on EC2, especially with its latest version 3.12, here’s a concise guide to get you there.
Step 1: Update Your EC2 Instance
First things first—always ensure your instance is up-to-date. Open your terminal and connect to your EC2 instance. Then execute:
sudo yum update -y
Keeping your instance updated avoids potential security vulnerabilities and ensures a smoother installation process.
Step 2: Enable the Extra Packages for Enterprise Linux (EPEL) Repository
Amazon Linux doesn’t come with direct access to all available packages by default. To access additional software packages, you’ll need to enable the EPEL repository, which provides a substantial number of extra packages for your Linux instance.
To enable EPEL, type:
sudo amazon-linux-extras install epel
Once EPEL is active, you’ll have more package options at your disposal, including newer Python versions.
Step 3: Install Python 3.12
With the repository in place, you’re now ready to install the latest Python version. Execute the following command:
sudo amazon-linux-extras install python3.12
This command installs Python 3.12 along with its package manager, pip
, ensuring you can easily manage additional Python packages.
Step 4: Verify the Installation
Make sure the installation was successful by checking the Python version:
python3 --version
You should see an output similar to Python 3.12.x
, confirming that the installation is complete.
Step 5: Set Up a Python Virtual Environment
For isolated and manageable package installations, it’s helpful to create a virtual environment. Follow these steps:
-
Install
venv
:python3 -m pip install --upgrade pip
-
Create a new virtual environment:
python3 -m venv myenv
-
Activate the virtual environment:
source myenv/bin/activate
Once the environment is activated, you can install additional packages within this isolated setup using pip
.
With these steps, your EC2 instance will be ready to harness Python 3.12’s features for any project you wish to tackle.