Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Updating version of python on Google Colab

I need to update the default python version in Google Colab to version 3.9 in order to install some packages via poetry. However, when I update python I seem to lose the ability to install anything at all. I’m updating python by following the accepted answer here, which works in so far as giving me the version of python I need:

#install python 3.9
!sudo apt-get update -y
!sudo apt-get install python3.9

#change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2

#check python version
!python --version
# returns Python 3.9.13

However, when I then try to install poetry via !pip3 install poetry I get the following response:

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

Curiously, when I try !pip3 install poetry before updating python it works. However, if I install poetry first, then update python, when I try to install the variopus packages I need via !poetry install I get a similar traceback error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Traceback (most recent call last):
  File "/usr/local/bin/poetry", line 5, in <module>
    from poetry.console import main
ModuleNotFoundError: No module named 'poetry'

Long-story-short, I can’t work out how I can get the version 3.9 of python in Colab AND poetry to work.

>Solution :

Yes you need to install pip with !sudo apt-get install python-pip

Then you might need the distutils lib !sudo apt install python3.9-distutils

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading