0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Google ColabでPythonのバージョンを変更する

Last updated at Posted at 2024-11-04

きっかけ

GoogleColabにインストールされているPythonのバージョンでは動かないライブラリを扱いたかったから。

変更方法

以下を実行することで任意のバージョンのPython(以下の例ではPython3.7)をGoogleColabにインストールできる。

!sudo add-apt-repository -y ppa:deadsnakes/ppa
!sudo apt-get -y update
!sudo apt-get -y install python3.7
!sudo apt-get -y install python3.7-dev
!sudo apt-get -y install python3-pip
!sudo apt-get -y install python3.7-distutils

!python3.7 -m pip install --upgrade setuptools
!python3.7 -m pip install --upgrade pip
!python3.7 -m pip install --upgrade distlib

!sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
!sudo update-alternatives --set python /usr/bin/python3.7
!sudo ln -sf /usr/bin/python /usr/local/bin/python

!python -V
# Python 3.7.17

これでわざわざpython3.7 -m pip ...としなくてもpip ...で動作するようにできる。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?