Deana talks you through setting up
an isolated Python 3.4 environment using


How do I create an isolated Python 3.4 environment with Boto 3 on Amazon EC2 using virtualenv?

These instructions are for an EC2 instance running Amazon Linux.

1. Connect to your EC2 Linux instance using SSH. For more information, see Connecting to Your Linux Instance Using SSH.

2. Perform a yum install update.

[ec2-user ~]$ sudo yum install update

3. Launch Python to see the default version. As you can see, Amazon Linux comes with Python 2.7 installed and enabled by default:

[ec2-user ~]$ which python


[ec2-user ~]$ python

Python 2.7.10 (default, Dec 8 2015, 18:25:23)

[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2

Type "help", "copyright", "credits" or "license" for more information.


4. Amazon Linux also comes with Boto for Python 2 installed:

>>> import boto            # no errors

>>> exit()

5. Install Python 3.4 using the following command:

[ec2-user ~]$ sudo yum install python34

Confirm the install was successful:

[ec2-user ~]$ which python3.4


6. Create a folder to hold your virtualenv environments and cd into it. In the following example, the environments are stored in the “venv” directory, under the “ec2-user” directory.

[ec2-user ~]$ pwd


[ec2-user ~]$ mkdir venv

[ec2-user ~]$ cd venv

[ec2-user ~]$ pwd


7. Amazon Linux comes with virtualenv already installed, so create the python34 environment:

[ec2-user ~]$ virtualenv -p /usr/bin/python3.4 python34

Running virtualenv with interpreter /usr/bin/python3.4

Using base prefix '/usr'

New python executable in python34/bin/python3.4

Also creating executable in python34/bin/python

Installing setuptools, pip...done.

8. Activate the environment by sourcing the activate file in the “bin” directory under your project folder.

[ec2-user ~]$ source /home/ec2-user/venv/python34/bin/activate

9. You are now referencing the new environment.

[ec2-user ~]$ which python

~/venv/python34/bin/python   # python34 is now the default

10. Install Boto 3 from within the python34 environment using the following command:

[ec2-user ~]$ pip install boto3

11. Run Python using the python3 executable. You can also import the Boto 3 SDK:

[ec2-user ~]$ python

Python 3.4.3 (default, Apr 1 2015, 18:10:40)

[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import boto3           # no error

>>> exit()

12. Deactivate the python34 environment with the following command:

[ec2-user ~]$ deactivate

Run the “which” command to confirm you’ve been returned to the default environment:

[ec2-user ~]$ which python


13. If you want to activate the python34 environment automatically every time you log in, add it to your .bashrc file:

[ec2-user ~]$ echo "source /home/ec2-user/venv/python34/bin/activate" >> /home/ec2-user/.bashrc

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center.

Published: 2016-06-24