Score:1

How do I upgrade my python installation, and pip?

cn flag

On my Ubuntu server, Python 3.8 and 2-something is installed.

I want to upgrade to Python 3.10, and I installed it from a ppa. But 3.8 is still installed, and pip --version shows pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

I tried running a script with this command: python3.10 myscript.py but this fails because this script is using the websockets package. If I run pip install websockets it says that it is already installed. But it isn't installed for Python 3.10, only 3.8.

So in short: How do I upgrade to Python and pip to version 3.10?

EDIT: these are the commands I used to upgrade Python to 3.10

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.10
Nmath avatar
ng flag
Several Ubuntu packages rely on python. If you change the installed version, you can break your system. Instead, set up a python environment that will not mess up your entire Ubuntu installation
ozcnakd avatar
id flag
I agree with @Nmath . Creating virtualenv is safer option.
birgersp avatar
cn flag
Appreciate the advice. This is what I ended up doing, and using an updated version if Python in a virtual env solved the issue I had. Thank you!
Score:2
id flag

There is two options

  • Changing ubuntu's python3:

    sudo mv /usr/bin/python3 /usr/bin/python3_backup & sudo ln -s /usr/bin/python3.10 /usr/bin/python3

  • Creating a virtualenv and use that env python3.10 -m venv venv_folder source venv_folder/bin/activate pip .. python ..

After finished your job with this env, you can just type deactivate and venv will close.

Second method is a workaround solution.

birgersp avatar
cn flag
Your answer solved my initial issue, but it doesn't really answer my SO question. Best I can give you is an upvote. Thank you though!
ozcnakd avatar
id flag
Can you try python3.10 -m pip install websockets ? I will also try something else after that, i'll edit this comment.
birgersp avatar
cn flag
`python3.10 -m pip install websockets` gave me `ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)`
ozcnakd avatar
id flag
@birgersp I found a solution. Changing name or deleting /usr/bin/python3 and creating symlink to python3.10 updates pip's python. sudo mv /usr/bin/python3 /usr/bin/python3_backup & sudo ln -s /usr/bin/python3.10 /usr/bin/python3 If it's work for you, i can change my answer.
birgersp avatar
cn flag
Seems to be working!
ozcnakd avatar
id flag
Ok super, i edited answer.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.