How can I use the earlier version of Python i.e version 2.x?
Under the ‘change runtime’ option – I can see the option for selecting hardware accelerator.
You can use these 2 shortcuts to create a Python 2 Colab.
bit.ly/colabpy2
colab.to/py2
They will forward to this URL.
https://colab.research.google.com/notebook#create=true&language=python2
Update 2022
Now the Python 2 kernel is removed. The simple method above no longer works. You may try the difficult method I used with Python 3.10 if you really must.
3
Python 2 reached its end of life on January 1, 2020, and is no longer supported by the Python developer community. Because of that, Colab is in the process of deprecating Python 2 runtimes; see https://research.google.com/colaboratory/faq.html#python-2-deprecation for details.
Presently, there is no way to change to Python 2 via the Colab UI, but existing Python 2 notebooks will still connect to Python 2 for the time being. So, for example, if you open a notebook like this one: https://colab.research.google.com/gist/jakevdp/de56c474b41add4540deba2426534a49/empty-py2.ipynb and execute code, it will execute in Python 2 for now. I would suggest following that link, and then choosing File->Save A Copy In Drive to get your own copy of an empty Python 2 notebook.
But please be aware that at some point in the future, Python 2 runtimes will be entirely unavailable in Colab, even for existing notebooks that specify Python 2 in their metadata.
1
Python2 is deprecated now and is no longer available as a runtime in colab
If you are running some python program, you can use
!python2.7 your_program.py
instead of !python your_program.py
But if you want to execute some python2.7 code, I think that as mentioned in the previous answers, it is not possible.