简体   繁体   中英

Downgrade python version from 3.7 to 3.6 in google colab

Some python packages wont work in python 3.7. So wanted to downgrade the default python version in google colab.Is it possible to do? If so how to proceed.Please guide me..

You could install python 3.6 with miniconda :

%%bash

MINICONDA_INSTALLER_SCRIPT=Miniconda3-4.5.4-Linux-x86_64.sh
MINICONDA_PREFIX=/usr/local
wget https://repo.continuum.io/miniconda/$MINICONDA_INSTALLER_SCRIPT
chmod +x $MINICONDA_INSTALLER_SCRIPT
./$MINICONDA_INSTALLER_SCRIPT -b -f -p $MINICONDA_PREFIX

And add to path:

import sys
_ = (sys.path.append("/usr/local/lib/python3.6/site-packages"))

There are allready many versions Python in Colab. Maybe you can just use python3.6 -m pip install xxx to install model and run the code by python3.6 xx.py .

The following code snippet below will download Python 3.6 without any Colab pre-installed libraries (such as Tensorflow). You can install them later with pip, like !pip install tensorflow . Please note that this won't downgrade your default python in colab, rather it would provide a workaround to work with other python versions in colab. To run any python scripts with 3.6 version, use .python3.6 instead of !python

!add-apt-repository ppa:deadsnakes/ppa
!apt-get update
!apt-get install python3.6
!apt-get install python3.6-dev

!wget https://bootstrap.pypa.io/get-pip.py && python3.6 get-pip.py

import sys

sys.path[2] = '/usr/lib/python36.zip'
sys.path[3] = '/usr/lib/python3.6'
sys.path[4] = '/usr/lib/python3.6/lib-dynload'
sys.path[5] = '/usr/local/lib/python3.6/dist-packages'
sys.path[7] ='/usr/local/lib/python3.6/dist-packages/IPython/extensions'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM