0

I am using python 3.7 in google colab, but for some reason when I am connected with a linux server in google cloud the python becomes 2.7. How can I change it? Note that python 3.7 is already installled in the server.

I tried these things but weren't helpful.

apt update
sudo apt install python3-pip
alias pip='pip3'

I checked also these sites https://cloud.google.com/python/docs/setup#linux_2, How do I install Python 3.7 in google cloud shell but didn't solve my problem.

Edit By doing Runtime --> Change runtime I can see only this, which the options are 'non', 'gpu', 'tpu'. enter image description here

3 Answers3

0

You can check your Python version at the command line by running python --version. In Colab, we can enforce the Python version by clicking Runtime -> Change Runtime Type and selecting python3.

0

Python 2.7 is expected to be removed in Debian "testing", the basis of gLinux. This is expected to happen shortly after the next major version, Debian Bullseye, is released.

You need to migrate Python 2.7 code to Python 3 and remove python-is-python2 packages you might have installed.

When Python 2.7 is removed from gLinux, python-is-python2 will be uninstalled.

If you have software that requires /usr/bin/python to work, but can be used with Python 3, you should install python-is-python3.

You can change Python version by running the following commands in terminal:

pip install virtualenv

virtualenv venv --python=python3

This only works if you have Python2.7 installed at the system level (e.g. /usr/bin/python2.7).

You can find the path to your Python installation with

which python3

virtualenv venv --python=/usr/local/bin/python3

And check the version using python3 –version.

Srividya
  • 1,678
  • 3
  • 10
  • Thank you a lot. In the last line of code 'virtualenv venv --python=/usr/local/bin/python3' it says no such file in directory. Do you have any idea which is the problem? –  Aug 04 '21 at 11:43
  • Will you try using 'virtualenv venv --python = /usr/bin/python3`. – Srividya Aug 05 '21 at 03:45
0

So actually the answer of my question comes from this post How to completely uninstall python 2.7.13 on Ubuntu 16.04.

Everyone who have a similar problem the first thing that he/she should do is to unistall python 2.7 by using either

sudo apt install --reinstall python python-apt python2.7-minimal

or

sudo apt purge python2.x-minimal

and then install python 3.7, by using

sudo ln -s /usr/bin/python3 /usr/bin/python

sudo apt install -y python3-pip

sudo ln -s /usr/bin/pip3 /usr/bin/pip

# Confirm the new version of Python: 3
python --version