0

I created a new AL2 EC2. I see Python 2 is already installed.

How can I upgrade this to Python 3 WITHOUT using virtualenv? I would like to maintain ONLY ONE version of Python.

3
  • 1
    I'm going to guess something like "yum remove python" and "yum install python3". Those commands might not work but it's worth a go. Otherwise if Python3 isn't available for AL2 you can add a Python repo or move to an OS with more widely available packages like Ubuntu.
    – Tim
    Commented Mar 2, 2021 at 17:58
  • 1
    @Tim You can't because yum depends on python. I don't think there is a sane reason to want what the OP is requesting, anyway. Like many other distros, Amazon Linux calls Python 2 python and Python 3 python3 so there is no confusion if you leave Python 2 on your system.
    – tripleee
    Commented Mar 24, 2021 at 18:28
  • Interesting @tripleee. Guess the answer then is don't uninstall python2, just additionally install python3.
    – Tim
    Commented Mar 24, 2021 at 22:55

1 Answer 1

2

WARNING: it may break yum, because yum uses python2!!!

Make sure you don't have it already:

ls /usr/bin/python*
/usr/bin/python   /usr/bin/python2.7         /usr/bin/python2-config  /usr/bin/python3.7   /usr/bin/python-config
/usr/bin/python2  /usr/bin/python2.7-config  /usr/bin/python3         /usr/bin/python3.7m

if you do have and don't like to use python3 instead of just python, then

python --version
Python 2.7.18

update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
python --version
Python 3.7.10

You might also want:

ln -s /usr/bin/pip3 /usr/bin/pip
pip --version
pip 20.2.2 from /usr/lib/python3.7/site-packages/pip (python 3.7)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .