Colab kept using python3.7 dist-packages dispite python 3.9 installed and configured

Viewed 60

So I installed python 3.9 with the following in colab:

# @title install python 3.9
# %%capture

use_python3_9 = True #@param {type:"boolean"}
py_version = !python --version
if use_python3_9:
  if '3.9' not in py_version[0]:
    !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
    !sudo update-alternatives --config python

    # Install dist utlis
    !apt install python3.9-distutils

    # Install pip
    !apt-get install python3-pip
    !python -m pip install --upgrade pip

#check python version
!python --version
#3.9.6

Then I tried to install networkx with !pip install networkx==2.8.5

After I'm done, the colab kept using the 2.6.3 specified in python 3.7

when I do the folllowing:

import pkg_resources
pkg_resources.require("networkx==2.8.5")
import networkx
networkx.__version__

colab throws


VersionConflict: (networkx 2.6.3 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('networkx==2.8.5'))
0 Answers
Related