179

I'm trying to install python 3.x on an AWS EC2 instance and:

sudo yum install python3

doesn't work:

No package python3 available.

I've googled around and I can't find anyone else who has this problem so I'm asking here. Do I have to manually download and install it?

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
Jake_Howard
  • 2,533
  • 2
  • 15
  • 13
  • 1
    Possibly yes, it may not yet be available for Amazon Linux (or clarify if you're using a different OS). – Simeon Visser Dec 28 '14 at 00:07
  • possible duplicate of [Installing python3 on RHEL](http://stackoverflow.com/questions/8087184/installing-python3-on-rhel) – BMW Dec 28 '14 at 10:24
  • 1
    Hi, yes it's the 'standard' Amazon Linux OS. Happy to manually install but there are a few things missing ( and I thought it best to check before spending time messing about :) – Jake_Howard Dec 28 '14 at 11:15
  • @BMW the answer you linked to was helpful but not enough to get it working on its own. – Jake_Howard Dec 28 '14 at 11:38
  • Since the AMI underneath changes often, it may be useful to check the release notes for the most recent machine, available here: https://aws.amazon.com/amazon-linux-ami/#Release_Notes – slushy Dec 20 '16 at 17:03
  • 1
    Now i can run on Amazon Linux 2 AMI. sudo yum install python3. – Minh Hoàng Jul 02 '20 at 07:25

12 Answers12

307

If you do a

sudo yum list | grep python3

you will see that while they don't have a "python3" package, they do have a "python34" package, or a more recent release, such as "python36". Installing it is as easy as:

sudo yum install python34 python34-pip
Gowtham
  • 11,853
  • 12
  • 43
  • 64
TaborKelly
  • 3,446
  • 1
  • 17
  • 13
  • 1
    This seems to be the simpler answer. Did AWS update their packages between when @Jake_Howard posted an answer and you did? – Roman May 13 '15 at 04:12
  • I haven't verified that this is true, but I'll reward the best answer on trust. I'm not sure if they have upgraded since I answered, there are certainly a fair few blog posts out there outlining how to do it the old fashioned way. The even better approach that I found was just to use Ubuntu instead! :) – Jake_Howard May 30 '15 at 19:30
  • I think this method is best. The approach @Jake_Howard outlined worked for me in an arbitrary CentOS VM. However, I believe that answer still needs some editing in terms of what's performed as root. – blong Jul 30 '15 at 14:49
  • 9
    To use pip3 add the following symbolic link # ln -s /usr/bin/pip-3.4 /usr/bin/pip3 – Ray Vahey Aug 13 '16 at 12:18
  • 16
    `sudo yum install python34` doesn't work for me. It says `No package python34 available.` – Sohan Shirodkar Sep 01 '16 at 14:48
  • 3
    @SohanShirodkar you may have been unlucky and just caught a new release -- their September release moved to `python35` ... here's where you can see the newest releases: https://aws.amazon.com/amazon-linux-ami/#Release_Notes – slushy Dec 20 '16 at 17:04
  • Use @Jake_Howard 's answer, if you do not have access on your aws YUM manager to python 3. – Chad Van De Hey Jan 03 '17 at 20:51
  • 7
    In 2018, `sudo yum install python36` is also available. also don't forget to install latest pip: `python3 -m pip install --user --upgrade pip` and then you can `python3 -m pip install --user virtualenv` for a virtual env. ref: https://packaging.python.org/guides/installing-using-pip-and-virtualenv/ – Emmanuel N K Aug 13 '18 at 11:24
  • This answer, although acceptable, wasted my time uninstalling python 3.4 to install 3.6, since the version of python3 will not always be python34, as assumed by the answer. In fact, python 3.4 is being deprecated March 2019 by Django, being replaced by 3.6. – Samer Mar 28 '19 at 18:59
  • 1
    I can run 'sudo yum install python3 python3-pip' today. – GoYun.Info Mar 04 '20 at 15:05
  • `sudo yum install python36 python36-pip` worked for me, thanks !! – BEN HACHME EL HASSANE Oct 27 '20 at 19:04
84

Note: This may be obsolete for current versions of Amazon Linux 2 since late 2018 (see comments), you can now directly install it via yum install python3.

In Amazon Linux 2, there isn't a python3[4-6] in the default yum repos, instead there's the Amazon Extras Library.

sudo amazon-linux-extras install python3

If you want to set up isolated virtual environments with it; using yum install'd virtualenv tools don't seem to reliably work.

virtualenv --python=python3 my_venv

Calling the venv module/tool is less finicky, and you could double check it's what you want/expect with python3 --version beforehand.

python3 -m venv my_venv

Other things it can install (versions as of 18 Jan 18):

[ec2-user@x ~]$ amazon-linux-extras list
  0  ansible2   disabled  [ =2.4.2 ]
  1  emacs   disabled  [ =25.3 ]
  2  memcached1.5   disabled  [ =1.5.1 ]
  3  nginx1.12   disabled  [ =1.12.2 ]
  4  postgresql9.6   disabled  [ =9.6.6 ]
  5  python3=latest  enabled  [ =3.6.2 ]
  6  redis4.0   disabled  [ =4.0.5 ]
  7  R3.4   disabled  [ =3.4.3 ]
  8  rust1   disabled  [ =1.22.1 ]
  9  vim   disabled  [ =8.0 ]
 10  golang1.9   disabled  [ =1.9.2 ]
 11  ruby2.4   disabled  [ =2.4.2 ]
 12  nano   disabled  [ =2.9.1 ]
 13  php7.2   disabled  [ =7.2.0 ]
 14  lamp-mariadb10.2-php7.2   disabled  [ =10.2.10_7.2.0 ]
Nick T
  • 25,754
  • 12
  • 83
  • 121
  • "Topic python3 has end-of-support date of 2018-08-22" this is not supported anymore – zenbeni Apr 02 '19 at 09:37
  • @zenbeni did the default system Python get bumped to Python 3? – Nick T Apr 02 '19 at 20:47
  • @NickT python3-3.7.2-4.amzn2.0.1.x86_64 is actually installed through 'yum install python3' you don't use amazon linux extras anymore for python – zenbeni Apr 03 '19 at 08:53
  • 2
    I'm mildly confused why this keeps getting upvotes (4 in the last month) if it's now obsolete. – Nick T Apr 26 '19 at 21:15
47

Here are the steps I used to manually install python3 for anyone else who wants to do it as it's not super straight forward. EDIT: It's almost certainly easier to use the yum package manager (see other answers).

Note, you'll probably want to do sudo yum groupinstall 'Development Tools' before doing this otherwise pip won't install.

wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
tar zxvf Python-3.4.2.tgz
cd Python-3.4.2
sudo yum install gcc
./configure --prefix=/opt/python3
make
sudo yum install openssl-devel
sudo make install
sudo ln -s /opt/python3/bin/python3 /usr/bin/python3
python3 (should start the interpreter if it's worked (quit() to exit)
Jake_Howard
  • 2,533
  • 2
  • 15
  • 13
  • 8
    To use `pip3` also link it with `sudo ln -s /opt/python3/bin/pip3 /usr/bin/pip3`. – golmschenk Mar 17 '16 at 15:32
  • @xpmatteo - which bit is wrong? Is it just a step or the approach that you object to? – Jake_Howard Jun 11 '17 at 17:48
  • @Jake_Howard It is not true that the only way is to manually install Python3. That is certainly an option, but you can also do `yum install python35` as others have mentioned. If you would kindly amend your answer I will remove my downvote :) – xpmatteo Jun 15 '17 at 08:11
  • @xpmatteo - re-worded the answer to remove the incorrect phrase. For posterity: at the time of asking the question and posting the original answer, I wasn't aware of the ability to use yum with a specific version of python3 (see other answers), or these packages weren't available at the time of original writing. – Jake_Howard Jun 15 '17 at 14:17
  • Worked for me! This days you can use 3.7.2 instead of 3.4.2 – Cody Tookode Jan 30 '19 at 12:36
  • This is a very good answer, since you can use the same approach to install any version you want. The package manager does not include all. – srcolinas Oct 29 '20 at 12:46
  • I just built `3.9.16` from source because the `yum` repos only support 3.7.16 currently. Thanks @Jake_Howard, your approach worked for me. – 0xbe5077ed Jul 06 '23 at 21:18
27

EC2 (on the Amazon Linux AMI) currently supports python3.4 and python3.5.

sudo yum install python35
sudo yum install python35-pip
Mike D
  • 5,984
  • 4
  • 31
  • 31
Russ McFatter
  • 492
  • 4
  • 6
  • Props for this answer! Python3 is not `python3` on AWS instances by default. Very frustrating to swap between Ubuntu and AWS Linux when working! – Adam Link Nov 21 '17 at 07:53
  • This works and you can confirm if 3.5 is the latest you have with this command `sudo yum list | grep python3` and to once you've installed confirm by typing `pythono3 --version` - yes python3 as python will return v2. – Jeremy Thompson Jan 20 '21 at 05:14
  • sudo amazon-linux-extras install python3.8 – vaquar khan May 02 '23 at 23:34
21

As of Amazon Linux version 2017.09 python 3.6 is now available:

sudo yum install python36 python36-virtualenv python36-pip

See the Release Notes for more info and other packages

Realistic
  • 1,038
  • 1
  • 10
  • 20
4

Amazon Linux now supports python36.

python36-pip is not available. So need to follow a different route.

sudo yum install python36 python36-devel python36-libs python36-tools

# If you like to have pip3.6:
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
Sairam Krish
  • 10,158
  • 3
  • 55
  • 67
  • This is the easiest way that works in 2020 of all the others. – russellthehippo May 18 '20 at 21:49
  • 1
    This does not work on Amazon Linux 2 - `python36` and all other related packages are held in `amazon-linux-extras` now and don't install the expected packages which others may have as dependencies. – bsplosion Nov 03 '20 at 21:57
4

As @NickT said, there's no python3[4-6] in the default yum repos in Amazon Linux 2, as of today it uses 3.7 and looking at all answers here we can say it will be changed over time.

I was looking for python3.6 on Amazon Linux 2 but amazon-linux-extras shows a lot of options but no python at all. in fact, you can try to find the version you know in epel repo:

sudo amazon-linux-extras install epel

yum search python | grep "^python3..x8"

python34.x86_64 : Version 3 of the Python programming language aka Python 3000
python36.x86_64 : Interpreter of the Python programming language
Putnik
  • 5,925
  • 7
  • 38
  • 58
  • Unfortunately the only version it shows anymore now is python34.x86_64, they must've removed python36.x86_64 which is quite annoying. – dragon788 Jun 03 '20 at 23:26
3

Check the packages available

A> amazon-linux-extras

Find the required python package with version from the list

B> sodo amazon-linux-extras enable python<version_available>

C> sudo yum clean metadata && sudo yum install python<version_available>

Saurav Bhowmick
  • 308
  • 4
  • 16
1

Adding to all the answers already available for this question, I would like to add the steps I followed to install Python3 on AWS EC2 instance running CentOS 7. You can find the entire details at this link.

https://aws-labs.com/install-python-3-centos-7-2/

First, we need to enable SCL. SCL is a community project that allows you to build, install, and use multiple versions of software on the same system, without affecting system default packages.

sudo yum install centos-release-scl

Now that we have SCL repository, we can install the python3

sudo yum install rh-python36

To access Python 3.6 you need to launch a new shell instance using the Software Collection scl tool:

scl enable rh-python36 bash

If you check the Python version now you’ll notice that Python 3.6 is the default version

python --version

It is important to point out that Python 3.6 is the default Python version only in this shell session. If you exit the session or open a new session from another terminal Python 2.7 will be the default Python version.

Now, Install the python development tools by typing:

sudo yum groupinstall ‘Development Tools’

Now create a virtual environment so that the default python packages don't get messed up.

mkdir ~/my_new_project
cd ~/my_new_project
python -m venv my_project_venv

To use this virtual environment,

source my_project_venv/bin/activate

Now, you have your virtual environment set up with python3.

nambastha
  • 127
  • 14
0

try this

sudo yum install python34 python34-pip

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 28 '21 at 10:58
-4

On Debian derivatives such as Ubuntu, use apt. Check the apt repository for the versions of Python available to you. Then, run a command similar to the following, substituting the correct package name:

sudo apt-get install python3

On Red Hat and derivatives, use yum. Check the yum repository for the versions of Python available to you. Then, run a command similar to the following, substituting the correct package name:

sudo yum install python36

On SUSE and derivatives, use zypper. Check the repository for the versions of Python available to you. Then. run a command similar to the following, substituting the correct package name:

sudo zypper install python3
Light Bringer
  • 741
  • 7
  • 12
-4

Here is the one command to install python3 on Amazon linux ec2 instance:

$sudo yum install python3 -y

$python3 --version

Python 3.7.6

Pruthvi Chitrala
  • 176
  • 1
  • 3
  • 10