{"id":467,"date":"2022-01-31T10:25:08","date_gmt":"2022-01-31T10:25:08","guid":{"rendered":"https:\/\/mri.sbollmann.net\/?p=467"},"modified":"2022-01-31T10:25:09","modified_gmt":"2022-01-31T10:25:09","slug":"combining-conda-and-google-colab","status":"publish","type":"post","link":"https:\/\/mri.sbollmann.net\/index.php\/2022\/01\/31\/combining-conda-and-google-colab\/","title":{"rendered":"Combining conda and google colab"},"content":{"rendered":"\n<p>Sometimes it&#8217;s necessary to downgrade packages in google colab to restore compatibility with an older version (e.g. pytorch). One way of doing this is using conda within colab and a few tricks make this work. Here is the colab notebook: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/colab.research.google.com\/drive\/1W5UnflB8m1zo6lP1y11V78QczMRBI0FE?usp=sharing\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"772\" src=\"https:\/\/mri.sbollmann.net\/wp-content\/uploads\/2022\/01\/image-1024x772.png\" alt=\"\" class=\"wp-image-471\" srcset=\"https:\/\/mri.sbollmann.net\/wp-content\/uploads\/2022\/01\/image-1024x772.png 1024w, https:\/\/mri.sbollmann.net\/wp-content\/uploads\/2022\/01\/image-300x226.png 300w, https:\/\/mri.sbollmann.net\/wp-content\/uploads\/2022\/01\/image-768x579.png 768w, https:\/\/mri.sbollmann.net\/wp-content\/uploads\/2022\/01\/image-1536x1157.png 1536w, https:\/\/mri.sbollmann.net\/wp-content\/uploads\/2022\/01\/image.png 2025w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><a href=\"https:\/\/colab.research.google.com\/drive\/1W5UnflB8m1zo6lP1y11V78QczMRBI0FE?usp=sharing\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/colab.research.google.com\/drive\/1W5UnflB8m1zo6lP1y11V78QczMRBI0FE?usp=sharing<\/a><\/p>\n\n\n\n<p>Here a quick code gist:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Check Python version of colab - we need to match this in conda:\n!python --version\n\n%%bash\nMINICONDA_INSTALLER_SCRIPT=Miniconda3-py37_4.10.3-Linux-x86_64.sh\nMINICONDA_PREFIX=\/usr\/local\nwget https:\/\/repo.continuum.io\/miniconda\/$MINICONDA_INSTALLER_SCRIPT\nchmod +x $MINICONDA_INSTALLER_SCRIPT\n.\/$MINICONDA_INSTALLER_SCRIPT -b -f -p $MINICONDA_PREFIX\n\n!which conda # should return \/usr\/local\/bin\/conda\n!conda --version # should return 4.10.3\n!python --version # should return 3.7.10 but should actually match the one installed in colab, which is currently: 3.7.11\n\n%%bash\nconda install --channel defaults conda python=3.7 --yes\nconda update --channel defaults --all --yes\n\n!conda --version # now returns 4.11.0\n!python --version # now matches with colab :) 3.7.11\n\n!yes | conda install pytorch==1.6.0 torchvision==0.7.0 -c pytorch\n\nimport sys\nsys.path # dist-packages is colab and site-packages is conda -> problem is that colab packages get loaded before conda\n\nsys.path.insert(0,\"\/usr\/local\/lib\/python3.7\/site-packages\")\n\n# So this will now use conda's torch with cuda 10\nimport torch\nprint(torch.version.cuda)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes it&#8217;s necessary to downgrade packages in google colab to restore compatibility with an older version (e.g. pytorch). One way of doing this is using conda within colab and a few tricks make this work. Here is the colab notebook: https:\/\/colab.research.google.com\/drive\/1W5UnflB8m1zo6lP1y11V78QczMRBI0FE?usp=sharing Here a quick code gist:<\/p>\n","protected":false},"author":1,"featured_media":471,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-reproducibility"],"jetpack_featured_media_url":"https:\/\/mri.sbollmann.net\/wp-content\/uploads\/2022\/01\/image.png","_links":{"self":[{"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":3,"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/posts\/467\/revisions\/472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/media\/471"}],"wp:attachment":[{"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mri.sbollmann.net\/index.php\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}