how to import conda packages into google colab?

跟風遠走 提交于 2019-12-21 20:05:16

问题


Hi I was able to install packages in google colab with pip, using:

!pip install....

but i am not able to install any package from conda-forge. I tried:

!conda install -c conda-forge cartopy

thanks in advance!


回答1:


One way to get it is to just Unzip the conda package to a directory directly.

  1. Get you required conda package from anaconda.org, download it.

  2. Decompress them and copy them into the library path

Here's an example to install faiss from anaconda using this way. https://gist.github.com/korakot/d0a49d7280bd3fb856ae6517bfe8da7a




回答2:


Another option (that I've not tried) is to connect to a custom runtime (kernel in Jupyter parlance). https://research.google.com/colaboratory/local-runtimes.html

The workflow would be:

  • create a conda environment with the things you want + jupyter_http_over_ws
  • start a notebook on your machine and connect colab as described

This may not be what you are looking for though as it does require local installations (and is therefore no longer zero-install).




回答3:


I use the decompress method with cartopy. Here's the result.

# get package then extract
!wget https://anaconda.org/conda-forge/cartopy/0.16.0/download/linux-64/cartopy-0.16.0-py36h81b52dc_2.tar.bz2
!tar xvjf cartopy-0.16.0-py36h81b52dc_2.tar.bz2
!cp -r lib/python3.6/site-packages/* /usr/local/lib/python3.6/dist-packages/
# install dependencies
!pip install shapely pyshp
!apt install libproj-dev libgeos-dev
# finally
import cartopy



回答4:


In general, this is a way to install a package in conda from Colab:

!wget https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
!bash Miniconda3-4.5.4-Linux-x86_64.sh -bfp /usr/local
# Append path to be able to run packages installed with conda
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')
# Install packages from Anaconda
!conda install -y [package]

This works for packages like -c pslmodels taxcalc (notebook).

However, cartopy is a complicated package that's creating problems here, I think because the above requires an older version of conda*, which is no longer compatible with cartopy. Here's a Colab notebook that uses this version and fails because cartopy requires the shapefile package, and this is one that uses the latest version of conda and isn't recognized upon import.

* For example, here are versions of the taxcalc notebook that install the latest installer and run conda update conda before installing taxcalc; import taxcalc isn't recognized in either case. See this GitHub issue.



来源:https://stackoverflow.com/questions/53000670/how-to-import-conda-packages-into-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!