0

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:

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.

cookie1986
  • 865
  • 12
  • 27

1 Answers1

1

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

T0w0T
  • 66
  • 7
  • Thanks - that gets me a little further along, but gives me another traceback error ```ModuleNotFoundError: No module named 'pip._internal'``` – cookie1986 Aug 04 '22 at 16:28
  • so try with !sudo apt-get install python3-pip – T0w0T Aug 04 '22 at 16:31
  • 1
    That seemed to give the same error. following the answer [here](https://askubuntu.com/questions/1025189/pip-is-not-working-importerror-no-module-named-pip-internal) though seems to have solved the problem. – cookie1986 Aug 04 '22 at 16:32
  • 1
    Maybe because you installed and deleted it before installing pip again ? – T0w0T Aug 04 '22 at 16:34