Skip to content

Instantly share code, notes, and snippets.

@kargaranamir
Last active January 3, 2023 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kargaranamir/e0b7910fed0a3189563d9254c7a2c439 to your computer and use it in GitHub Desktop.
Save kargaranamir/e0b7910fed0a3189563d9254c7a2c439 to your computer and use it in GitHub Desktop.
Use different version of Python in Google Colab (Python 3.9 or Python 3.10)
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Google colab python3.9 or python3.10.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"## Use different version of Python in Google Colab (Python 3.9 or Python 3.10)"
],
"metadata": {
"id": "UtfrQgGWwIhY"
}
},
{
"cell_type": "code",
"source": [
"## for python 3.10, run this cell\n",
"!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py310_22.11.1-1-Linux-x86_64.sh\n",
"!chmod +x mini.sh\n",
"!bash ./mini.sh -b -f -p /usr/local\n",
"!conda install -q -y jupyter\n",
"!conda install -q -y google-colab -c conda-forge\n",
"!python -m ipykernel install --name \"py310\" --user"
],
"metadata": {
"id": "EBcJMsi6viLZ"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"## for python 3.9 run this cell\n",
"!wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-x86_64.sh\n",
"!chmod +x mini.sh\n",
"!bash ./mini.sh -b -f -p /usr/local\n",
"!conda install -q -y jupyter\n",
"!conda install -q -y google-colab -c conda-forge\n",
"!python -m ipykernel install --name \"py39\" --user"
],
"metadata": {
"id": "2WxCQgO5SHOb"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"! python3 --version"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tLDriuO8pb7c",
"outputId": "815f1345-002b-4af7-9b51-9f2ee1df1118"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Python 3.10.8\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"!python3 -m pip install numpy"
],
"metadata": {
"id": "uoQheE-PqY5x"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"%%writefile code.py\n",
"\n",
"import numpy as np\n",
"print(np.arange(15).reshape(3, 5))"
],
"metadata": {
"id": "HbDerwdZSbmO"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"! python3 code.py"
],
"metadata": {
"id": "MuwKOO72pXQW"
},
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment