|# A virtualenv running Python3.6 on Amazon Linux/EC2 (approximately) simulates the Python 3.6 Docker container used by Lambda|
|# and can be used for developing/testing Python 3.6 Lambda functions|
|# This script installs Python 3.6 on an EC2 instance running Amazon Linux and creates a virtualenv running this version of Python|
|# This is required because Amazon Linux does not come with Python 3.6 pre-installed|
|# and several packages available in Amazon Linux are not available in the Lambda Python 3.6 runtime|
|# The script has been tested successfully on a t2.micro EC2 instance (Root device type: ebs; Virtualization type: hvm)|
|# running Amazon Linux AMI 2017.03.0 (HVM), SSD Volume Type - ami-c58c1dd3|
|# and was developed with the help of AWS Support|
|# The steps in this script are:|
|# - install pre-reqs|
|# - install Python 3.6|
|# - create virtualenv|
|# install pre-requisites|
|sudo yum -y groupinstall development|
|sudo yum -y install zlib-devel|
|sudo yum -y install openssl-devel|
|# Installing openssl-devel alone seems to result in SSL errors in pip (see https://medium.com/@moreless/pip-complains-there-is-no-ssl-support-in-python-edbdce548852)|
|# Need to install OpenSSL also to avoid these errors|
|tar -zxvf OpenSSL_1_0_2l.tar.gz|
|sudo make install|
|rm -rf openssl-OpenSSL_1_0_2l/|
|# Install Python 3.6|
|tar xJf Python-3.6.0.tar.xz|
|sudo make install|
|sudo rm -rf Python-3.6.0|
|# Create virtualenv running Python 3.6|
|sudo pip install --upgrade virtualenv|
|virtualenv -p python3 MYVENV|
|# Python 3.6.0|
For Python3.6.8 this script didn't work. After all the work it says pip configured with SSL but ssl library is missing.
I believe that if I would use make install I won't have to remove the old python 3.6.2 (that comes with AMI Extra).
Excellent steps few updates from me.
I was using RHEL 7.6 AWS.
In addition, on step #8, the
There is an
You can enable
If you are doing this in Docker for a deployable "builder" you probably don't want to use
Personally I'm both lazy and OCD so I've gotten tired of handling the various quirks as new Python versions come out and just use Pyenv to install different versions of Python than what are available in the official repositories (on many distros and macOS and Windows).
Sadly it appears in our specific use case we ended up needing to use
Skeleton of an AmazonLinux Dockerfile, can basically swap out the first 3 lines of the
Here's an easy copy-paste install script for Python 3.6.12 on the default Amazon Linux 2 EC2 instance, based on the replies above.
Then run Python3 with:
And use pip with: