Last active
July 20, 2021 11:34
-
-
Save grimelda/2f1d1e382b0b3984e95f9f2582848613 to your computer and use it in GitHub Desktop.
codecarbon_import_troubleshooting.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "codecarbon_import_troubleshooting.ipynb", | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "JilvP5jYHNzW" | |
}, | |
"source": [ | |
"# Codecarbon troubleshooting import and install\n", | |
"Importing CodeCarbon does not work properly in the Google Colab environment, because a `ContextualVersionConflict` pops up on first run (or after Runtime > Factory reset runtime). This severely limits the usability of this library in the Colab environment, because for wide spread use it is not feasible to ask practitioners to restart the kernel after every initialisation.\n", | |
"\n", | |
"Further description and full dump of error in issue #108 https://github.com/mlco2/codecarbon/issues/112 " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "O0m1VX41mfMr" | |
}, | |
"source": [ | |
"## Temporary workaround including kernel restart" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 277 | |
}, | |
"id": "qJmSMlr3mA5F", | |
"outputId": "50de7c11-951c-4efc-a73c-4a7826df0627" | |
}, | |
"source": [ | |
"#@markdown Workaround step 1: upgrade pytz and prompt kernel restart prompt\n", | |
"!pip install --upgrade pytz" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (2018.9)\n", | |
"Collecting pytz\n", | |
" Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)\n", | |
"\u001b[K |████████████████████████████████| 510 kB 4.7 MB/s \n", | |
"\u001b[?25hInstalling collected packages: pytz\n", | |
" Attempting uninstall: pytz\n", | |
" Found existing installation: pytz 2018.9\n", | |
" Uninstalling pytz-2018.9:\n", | |
" Successfully uninstalled pytz-2018.9\n", | |
"Successfully installed pytz-2021.1\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.colab-display-data+json": { | |
"pip_warning": { | |
"packages": [ | |
"pytz" | |
] | |
} | |
} | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "eK_YtSd8mXTd", | |
"outputId": "5573cb47-7cb0-4c06-cb0e-723b75880e10" | |
}, | |
"source": [ | |
"#@markdown Workaround step 2: import codecarbon without errors\n", | |
"!pip install --upgrade tzlocal\n", | |
"!pip install --upgrade codecarbon\n", | |
"from codecarbon import track_emissions\n" | |
], | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Requirement already satisfied: tzlocal in /usr/local/lib/python3.7/dist-packages (2.1)\n", | |
"Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from tzlocal) (2021.1)\n", | |
"Collecting codecarbon\n", | |
" Using cached codecarbon-1.2.0-py3-none-any.whl (135 kB)\n", | |
"Collecting dash-bootstrap-components\n", | |
" Using cached dash_bootstrap_components-0.12.2-py3-none-any.whl (191 kB)\n", | |
"Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from codecarbon) (1.1.5)\n", | |
"Collecting fire\n", | |
" Using cached fire-0.4.0.tar.gz (87 kB)\n", | |
"Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from codecarbon) (2.23.0)\n", | |
"Collecting pynvml\n", | |
" Using cached pynvml-11.0.0-py3-none-any.whl (46 kB)\n", | |
"Collecting py-cpuinfo\n", | |
" Using cached py-cpuinfo-8.0.0.tar.gz (99 kB)\n", | |
"Collecting APScheduler\n", | |
" Using cached APScheduler-3.7.0-py2.py3-none-any.whl (59 kB)\n", | |
"Collecting dash\n", | |
" Using cached dash-1.21.0.tar.gz (1.1 MB)\n", | |
"Requirement already satisfied: tzlocal~=2.0 in /usr/local/lib/python3.7/dist-packages (from APScheduler->codecarbon) (2.1)\n", | |
"Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from APScheduler->codecarbon) (2021.1)\n", | |
"Requirement already satisfied: setuptools>=0.7 in /usr/local/lib/python3.7/dist-packages (from APScheduler->codecarbon) (57.2.0)\n", | |
"Requirement already satisfied: six>=1.4.0 in /usr/local/lib/python3.7/dist-packages (from APScheduler->codecarbon) (1.15.0)\n", | |
"Requirement already satisfied: Flask>=1.0.4 in /usr/local/lib/python3.7/dist-packages (from dash->codecarbon) (1.1.4)\n", | |
"Collecting flask-compress\n", | |
" Using cached Flask_Compress-1.10.1-py3-none-any.whl (7.9 kB)\n", | |
"Requirement already satisfied: plotly in /usr/local/lib/python3.7/dist-packages (from dash->codecarbon) (4.4.1)\n", | |
"Collecting dash-core-components==1.17.1\n", | |
" Using cached dash_core_components-1.17.1.tar.gz (3.7 MB)\n", | |
"Collecting dash-html-components==1.1.4\n", | |
" Using cached dash_html_components-1.1.4.tar.gz (83 kB)\n", | |
"Collecting dash-table==4.12.0\n", | |
" Downloading dash_table-4.12.0.tar.gz (1.8 MB)\n", | |
"\u001b[K |████████████████████████████████| 1.8 MB 4.4 MB/s \n", | |
"\u001b[?25hRequirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from dash->codecarbon) (0.16.0)\n", | |
"Requirement already satisfied: itsdangerous<2.0,>=0.24 in /usr/local/lib/python3.7/dist-packages (from Flask>=1.0.4->dash->codecarbon) (1.1.0)\n", | |
"Requirement already satisfied: click<8.0,>=5.1 in /usr/local/lib/python3.7/dist-packages (from Flask>=1.0.4->dash->codecarbon) (7.1.2)\n", | |
"Requirement already satisfied: Werkzeug<2.0,>=0.15 in /usr/local/lib/python3.7/dist-packages (from Flask>=1.0.4->dash->codecarbon) (1.0.1)\n", | |
"Requirement already satisfied: Jinja2<3.0,>=2.10.1 in /usr/local/lib/python3.7/dist-packages (from Flask>=1.0.4->dash->codecarbon) (2.11.3)\n", | |
"Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/dist-packages (from Jinja2<3.0,>=2.10.1->Flask>=1.0.4->dash->codecarbon) (2.0.1)\n", | |
"Requirement already satisfied: termcolor in /usr/local/lib/python3.7/dist-packages (from fire->codecarbon) (1.1.0)\n", | |
"Collecting brotli\n", | |
" Downloading Brotli-1.0.9-cp37-cp37m-manylinux1_x86_64.whl (357 kB)\n", | |
"\u001b[K |████████████████████████████████| 357 kB 32.7 MB/s \n", | |
"\u001b[?25hRequirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->codecarbon) (2.8.1)\n", | |
"Requirement already satisfied: numpy>=1.15.4 in /usr/local/lib/python3.7/dist-packages (from pandas->codecarbon) (1.19.5)\n", | |
"Requirement already satisfied: retrying>=1.3.3 in /usr/local/lib/python3.7/dist-packages (from plotly->dash->codecarbon) (1.3.3)\n", | |
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->codecarbon) (2021.5.30)\n", | |
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->codecarbon) (2.10)\n", | |
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->codecarbon) (1.24.3)\n", | |
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->codecarbon) (3.0.4)\n", | |
"Building wheels for collected packages: dash, dash-core-components, dash-html-components, dash-table, fire, py-cpuinfo\n", | |
" Building wheel for dash (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for dash: filename=dash-1.21.0-py3-none-any.whl size=1100489 sha256=d9f94ef3fa23412804d98b6ae7fa9415c1acb8f7a4274224c63ca3ddab5341b9\n", | |
" Stored in directory: /root/.cache/pip/wheels/59/a4/f1/a7140afcad8dbaa3b1b12ef80843d29403d6ecca1c2f397948\n", | |
" Building wheel for dash-core-components (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for dash-core-components: filename=dash_core_components-1.17.1-py3-none-any.whl size=3738995 sha256=701e4fffdbc548611b07621182296588c710c6230ff7415ecd2339bdd6b75a67\n", | |
" Stored in directory: /root/.cache/pip/wheels/ca/5b/fb/a135a7bf8e21223e4104aa5526a5173a20b64fe7fcd055b999\n", | |
" Building wheel for dash-html-components (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for dash-html-components: filename=dash_html_components-1.1.4-py3-none-any.whl size=319771 sha256=a71a574376a3dc648b84b23c39309e191ebb2aebe77e08a672bca97d11264040\n", | |
" Stored in directory: /root/.cache/pip/wheels/51/d7/5f/5730b784b5333941740a0dfc57b10395c3507b35ddac112ac0\n", | |
" Building wheel for dash-table (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for dash-table: filename=dash_table-4.12.0-py3-none-any.whl size=1837674 sha256=1159e1af2c9ded647ba42b127e8b20159b2c9b4f2fd9a79504cdde97e7205d07\n", | |
" Stored in directory: /root/.cache/pip/wheels/5f/d4/8b/639186e25b7234dac44ba004cfb58ea5b39fe492085bda2a88\n", | |
" Building wheel for fire (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for fire: filename=fire-0.4.0-py2.py3-none-any.whl size=115943 sha256=8861a7931de11f1b98274d1cffbe36ec1e2c94a41b21b05ea8d5ba96d687659d\n", | |
" Stored in directory: /root/.cache/pip/wheels/8a/67/fb/2e8a12fa16661b9d5af1f654bd199366799740a85c64981226\n", | |
" Building wheel for py-cpuinfo (setup.py) ... \u001b[?25l\u001b[?25hdone\n", | |
" Created wheel for py-cpuinfo: filename=py_cpuinfo-8.0.0-py3-none-any.whl size=22257 sha256=f5acf8ce3c034721edb063e8c00a48117b07f140ee151012b2e61307bfd2537f\n", | |
" Stored in directory: /root/.cache/pip/wheels/d2/f1/1f/041add21dc9c4220157f1bd2bd6afe1f1a49524c3396b94401\n", | |
"Successfully built dash dash-core-components dash-html-components dash-table fire py-cpuinfo\n", | |
"Installing collected packages: brotli, flask-compress, dash-table, dash-html-components, dash-core-components, dash, pynvml, py-cpuinfo, fire, dash-bootstrap-components, APScheduler, codecarbon\n", | |
"Successfully installed APScheduler-3.7.0 brotli-1.0.9 codecarbon-1.2.0 dash-1.21.0 dash-bootstrap-components-0.12.2 dash-core-components-1.17.1 dash-html-components-1.1.4 dash-table-4.12.0 fire-0.4.0 flask-compress-1.10.1 py-cpuinfo-8.0.0 pynvml-11.0.0\n" | |
], | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "IMapv3mPmZIA" | |
}, | |
"source": [ | |
"## Attempts to deal with version conflict without prompting kernel restart" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "WdCl9GHUFy55" | |
}, | |
"source": [ | |
"#@markdown Normal recommended import... DNW!\n", | |
"!pip install --upgrade codecarbon\n", | |
"from codecarbon import track_emissions\n", | |
"'''\n", | |
"ContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\n", | |
"'''\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "LHK2_2_kIzPJ" | |
}, | |
"source": [ | |
"#@markdown Force uninstall of tzlocal. DNW!\n", | |
"!pip uninstall -y tzlocal\n", | |
"'''\n", | |
"Uninstalling tzlocal-1.5.1:\n", | |
" Successfully uninstalled tzlocal-1.5.1\n", | |
"\\nContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\\n \n", | |
"'''\n", | |
"!pip install codecarbon\n", | |
"from codecarbon import track_emissions\n", | |
"'''\n", | |
"ContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\n", | |
"'''\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "8wdMzvwLD1NY" | |
}, | |
"source": [ | |
"#@markdown Force uninstall and upgradeinstall of tzlocal. DNW!\n", | |
"!pip uninstall -y tzlocal\n", | |
"!pip install --upgrade tzlocal\n", | |
"''' Successfully installed tzlocal-2.1 '''\n", | |
"!pip install codecarbon\n", | |
"from codecarbon import track_emissions\n", | |
"'''\n", | |
"ContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\n", | |
"'''\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "h23Bm1RKGkPT" | |
}, | |
"source": [ | |
"#@markdown Attempt kernel re-read files and update the in-memory version of tzlocal? DNW!\n", | |
"from importlib import reload\n", | |
"import tzlocal\n", | |
"!pip uninstall -y tzlocal \n", | |
"!pip install --force-reinstall tzlocal==2.0\n", | |
"reload(tzlocal)\n", | |
"'''\n", | |
"WARNING: The following packages were previously imported in this runtime:\n", | |
" [pytz,tzlocal] \n", | |
"You must restart the runtime in order to use newly installed versions.\n", | |
"'''\n", | |
"!pip install codecarbon\n", | |
"from codecarbon import track_emissions\n", | |
"'''\n", | |
"ContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\n", | |
"'''" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "kBcjfa2BO3FS" | |
}, | |
"source": [ | |
"#@markdown Force upgradeinstall of all packages mentioned in errors. DNW!\n", | |
"!pip install --upgrade tzlocal pytz APScheduler\n", | |
"'''\n", | |
"Successfully installed APScheduler-3.7.0 pytz-2021.1 tzlocal-2.1\n", | |
"WARNING: The following packages were previously imported in this runtime:\n", | |
" [pytz]\n", | |
"You must restart the runtime in order to use newly installed versions.\n", | |
"\\nContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\\n\n", | |
"'''\n", | |
"!pip install codecarbon\n", | |
"from codecarbon import track_emissions\n", | |
"'''\n", | |
"ContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\n", | |
"'''\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "WORZz1xUItCs" | |
}, | |
"source": [ | |
"#@markdown Force reinstall pytz. DNW!\n", | |
"!pip install --force-reinstall pytz==2021.1\n", | |
"'''\n", | |
"WARNING: The following packages were previously imported in this runtime:\n", | |
" [pytz]\n", | |
"You must restart the runtime in order to use newly installed versions.\n", | |
"\\nContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\\n\n", | |
"'''\n", | |
"!pip install codecarbon\n", | |
"from codecarbon import track_emissions\n", | |
"'''\n", | |
"ContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\n", | |
"'''\n" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 261 | |
}, | |
"id": "pnssFglFRcwK", | |
"outputId": "e4da7b03-14ad-4f2c-f8fa-c8bfb1ba1017" | |
}, | |
"source": [ | |
"#@markdown Force reinstall and reload pytz. DNW!\n", | |
"from importlib import reload\n", | |
"import pytz\n", | |
"!pip uninstall -y pytz \n", | |
"!pip install --force-reinstall pytz==2021.1\n", | |
"reload(pytz)\n", | |
"'''\n", | |
"WARNING: The following packages were previously imported in this runtime:\n", | |
" [pytz]\n", | |
"You must restart the runtime in order to use newly installed versions.\n", | |
"\\nContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\\n\n", | |
"'''\n", | |
"!pip install codecarbon\n", | |
"from codecarbon import track_emissions\n", | |
"'''\n", | |
"ContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\n", | |
"'''\n" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Found existing installation: pytz 2018.9\n", | |
"Uninstalling pytz-2018.9:\n", | |
" Successfully uninstalled pytz-2018.9\n", | |
"Collecting pytz==2021.1\n", | |
" Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)\n", | |
"\u001b[K |████████████████████████████████| 510 kB 15.2 MB/s \n", | |
"\u001b[?25hInstalling collected packages: pytz\n", | |
"Successfully installed pytz-2021.1\n" | |
], | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/vnd.colab-display-data+json": { | |
"pip_warning": { | |
"packages": [ | |
"pytz" | |
] | |
} | |
} | |
}, | |
"metadata": { | |
"tags": [] | |
} | |
}, | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
}, | |
"text/plain": [ | |
"\"\\nContextualVersionConflict: (tzlocal 1.5.1 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('tzlocal~=2.0'), {'APScheduler'})\\n\"" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 1 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment