Install python 3, pip 3, and virtualenv in Amazon Linux 2

Today we're going to configure an AWS EC2 instance so we can create a virtual environment to run our Python 3 projects. We assume you've already created the instance and SSH'd into it. Let's get to it.

#let's update all the packages on the system.
sudo yum update

Next we're going to install python 3 and pip 3. Neither are installed on the system by default. Python 2 is installed at /usr/bin/python

sudo yum install python3 pip3

Now we'll install virtualenv so we can create python virtual environments.

sudo pip3 install virtualenv

Let's create our first first environment. This will create a folder named your_project_name. The environment is also installed in this folder.

virtualenv your_project_name

If you'd like to use python 2 you create your virtual environment like this

virtualenv -p /usr/bin/python your_project_name

The next thing you'll do is activate your virtual environment. You'll see you're shell session prefixed with (your_project_name) after you do this.

source your_project_name/bin/activate

Assuming you used python 3, you can see that python is not pointing to python 2. It's pointing to python 3.

python --version
#Python 3.7.4

#And you'll see the python 3 installation by running this
which python

#And pip 3
which pip

To deactivate your environment:


You can also see these instructions on our Gist

Pingbacks are closed.

Comments are closed.