4

My google colab python version is 3.8 and I need version 3.7. I try to install python 3.7, but after installation I get an error to install packages.

I use this method to install python 3.7:

!sudo apt-get install python3.7
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!sudo update-alternatives --config python3
!sudo apt install python3-pip

After running the Python version is:

!python --version
#Python 3.7.15

When I want to install a package (for example, torchfold):

!pip install torchfold

I get this error:

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._internal'

I could not solve it with the available resources, can you help me to solve this problem?

alireza
  • 41
  • 1
  • 1
  • 4

3 Answers3

3
-----To install specific version 3.7 of python in Google Colab-----
!sudo apt-get install python3.7
!sudo apt-get update -y
!sudo update-alternatives --install /usr/bin/python3 python3
/usr/bin/python3.7 1
!sudo update-alternatives --config python3

Select the specific number for 3.7

#Now check the version it will be 3.7

!python --version

#After that to install pip use these commands

James Flash
  • 528
  • 7
  • 15
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 16 '22 at 15:40
1

I used @M. Abdullah Fiaz but

-----To install specific version 3.7 of python in Google Colab-----

!sudo apt-get install python3.7
!sudo apt-get update -y
!sudo update-alternatives --install /usr/bin/python3 python3
/usr/bin/python3.7 1
!sudo update-alternatives --config python3

In "!sudo update-alternatives --config python3" I was being asked:

There are 3 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                 Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.10   2         auto mode
  1            /usr/bin/python3.10   2         manual mode
  2            /usr/bin/python3.7    2         manual mode
  3            /usr/bin/python3.8    1         manual mode

Press <enter> to keep the current choice[*], or type selection number: update-alternatives:

" So I changed it to:

!sudo update-alternatives --config python3 <<< '2'
starball
  • 20,030
  • 7
  • 43
  • 238
サルバドル
  • 379
  • 1
  • 6
  • 12
0

After running !sudo apt install python3-pip, force a pip reinstall using: !python -m pip install --upgrade --force-reinstall pip This is gonna ensure that pip is correct installed again.