Amazon has it's own Linux with extras, the command is:
sudo amazon-linux-extras install python3.8
taken from https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-linux.html but after installing 3.7 from there, there is the above update command appearing during the install telling how to upgrade. Ahh the convolution of hosted virtual machines, still easier than trying to get a console command line login on any other Linux on AWS.
It does rebuild the python to 3.8, cleaning up files from 3.7, so boom a clean build of 3.8 thanks to Amazon.
All that being said, the default "python" will still be 2.7 as there is no backward compatibility, and many think getting rid of 2.7 will cause problems.
So what NOT TO DO NEXT as we are done is:
sudo rm /usr/bin/python (which is only a link to /usr/bin/python2.7)
sudo ln -s /usr/bin/python3.8 /usr/bin/python
but usually peeps simply type python3.8 to specifically run the new version.
Answer from Light Bringer on Stack OverflowAmazon has it's own Linux with extras, the command is:
sudo amazon-linux-extras install python3.8
taken from https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-linux.html but after installing 3.7 from there, there is the above update command appearing during the install telling how to upgrade. Ahh the convolution of hosted virtual machines, still easier than trying to get a console command line login on any other Linux on AWS.
It does rebuild the python to 3.8, cleaning up files from 3.7, so boom a clean build of 3.8 thanks to Amazon.
All that being said, the default "python" will still be 2.7 as there is no backward compatibility, and many think getting rid of 2.7 will cause problems.
So what NOT TO DO NEXT as we are done is:
sudo rm /usr/bin/python (which is only a link to /usr/bin/python2.7)
sudo ln -s /usr/bin/python3.8 /usr/bin/python
but usually peeps simply type python3.8 to specifically run the new version.
These answers are now out of date as of Amazon Linux 2023. Amazon Linux 2023 FAQ
Q: Does AL2023 have Amazon-Linux-Extras like AL2?
A: No, AL2023 does not have extras. For higher-level software packages like language runtimes, we will use the quarterly release where we will add major/minor updates to packages as separate namespaced packages in addition to the default package provided in the repository. For example, default Python version in Amazon Linux 2023 may be 3.8, but we will add Python 3.9 (python39) as a separate namespaced package whenever it is made available. These additional packages will closely follow their upstream release cadence and support model and their support policies can be accessed by the package manager for compliance and security use cases. Default packages will continue to be supported throughout the life of AL2023.
Python is installed by default as python3 exact version is managed by Amazon. It is possible to pick a different version, but I have not found the instructions, since the currently install 3.9 works for my needs.
python3 --version
Python 3.9.16
python3x --version
always generated
-bash: python3x: command not found
regardless of choice of x
Python 3.9 in amazon-linux-extras
Amazon Linux 2 Python incompatibility woes
Unable to Add Python3.9 from amazon-linux-extras on Amazon Linux 2
How do I install Python 3 on an AWS EC2 instance? - Stack Overflow
A customer wants to continue to use Amazon Linux 2, I'm wanting to package some Python software for them, to be delivered via RPM.
Some dependencies are available in EPEL, and I used the Amazon instructions to install and enable that repo.
Using amazon-linux-extras installs Python 3.7, but nearly everything we need is in EPEL which is set for Python 3.6. So we insist on installing Python 3.6 from EPEL instead.
This makes we wonder how anyone is getting any work done with the Amazon Linux 2 image? Or am I doing something wrong? Is everyone just installing everything from source or using pip? The RPM packaging system appears in conflict with itself out of the box.
I am trying to install python 3.9 for AL 2 , it comes with python 3.7 . It is up-gradable upto 3.8 through amazon-linux-extras BUT i can't find python3.9 support in AL 2 .
If you do a
Copysudo 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:
Copysudo yum install python34 python34-pip
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.
Copysudo 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.
Copyvirtualenv --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.
Copypython3 -m venv my_venv
Other things it can install (versions as of 18 Jan 18):
Copy[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 ]