Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save norsec0de/b863e2d99e251b848b5e9fece1c45f1a to your computer and use it in GitHub Desktop.
Save norsec0de/b863e2d99e251b848b5e9fece1c45f1a to your computer and use it in GitHub Desktop.
Install Pyenv & Pipenv on AWS EC2 (Amazon Linux)

Install Pyenv & Pipenv on AWS EC2 (Amazon Linux)

Installation

Install Dependencies

Pyenv builds Python versions from source and therefore requires all the necessary build dependencies.

sudo yum install gcc zlib-devel bzip2 bzip2-devel patch readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel

Install Git

You'll need git installed to be able to clone the repositories

sudo yum install git

Clone the Pyenv Git Repository

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

Configure your '.bash_profile' file

echo ' ' >> ~/.bash_profile
echo '# Pyenv Configuration' >> ~/.bash_profile
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

Reinitialise your Shell

source ~/.bash_profile

Testing pyenv

pyenv

Configuration

To prevent any existing system dependencies from breaking, it's a good idea to setup pyenv with versions of the current existing python installations.

Make a note of the version numbers currently installed for python2 and python3.

$ python -V
Python 2.7.5

$ python3 -V
Python 3.6.8

Install matching systrem python versions

pyenv install 2.7.5
pyenv install 3.6.8

Configure Global python versions

pyenv global 3.6.8 2.7.5

Check that the versions are associated correctly

$ pyenv versions
  system
* 2.7.5 (set by /home/norsey/.pyenv/version)
* 3.6.8 (set by /home/norsey/.pyenv/version)

Upgrade Pip

pip install --upgrade pip

Install Pipenv

pip install --user pipenv
@Pax-nl
Copy link

Pax-nl commented Oct 18, 2023

Hi,

Thank you for this guide.. I needed to install some other packages for this to work: pyenv install 3.10

new yum install command:

sudo yum install gcc zlib-devel bzip2 bzip2-devel patch readline-devel sqlite sqlite-devel openssl11-devel tk-devel libffi-devel xz-devel

Errors I got:

ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib? 

solution:

   sudo yum remove openssl-devel
   sudo yum install -y openssl11-devel
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?

solution:

sudo yum install -y xz-devel

success:

Installing Python-3.10.13...
Installed Python-3.10.13 to /home/ec2-user/.pyenv/versions/3.10.13

Copy link

ghost commented Dec 16, 2023

Thanks!

@Amundeep-Dhaliwal
Copy link

Here are the packages that I installed in order to install python 3.10.10 via pyenv

sudo yum -y install openssl openssl11-devel xz-devel git-core gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel make bzip2 autoconf automake libtool bison sqlite sqlite-devel

@deepak-semasoftware
Copy link

Thanks a lot folks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment