I am able to get a conda environment setup and running from within Google Colab. However, this environment seems to be transient in nature. It does not show up in any new notebook I create, and I am not able to run the notebook normally. I have to run all my python code in one cell... But at least I know using conda to create my own environment in Google Colab is possible.

Check to see if conda is already installed

In [ ]:
!which conda

Nope, not installed. Go ahead and install it

I found a package cartopy that is not installed in my normal Google Colab environment. I want to use it so I will include it in my conda env create command below.

In [ ]:
import cartopy
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-14-a4ba129e3112> in <module>()
----> 1 import cartopy

ModuleNotFoundError: No module named 'cartopy'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To install cartopy, click the button below.
---------------------------------------------------------------------------
In [ ]:
# try to run the bare minimum to get a new conda env working
conda_path = ''
try:
    conda_path = !which conda
finally:
    print('')

if (len(conda_path) == 0):
    print('installing miniconda')
    !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
    !conda update conda -y -q
    !source /usr/local/etc/profile.d/conda.sh
    !conda init 
    !conda install -n root _license -y -q
else:
    print('found miniconda')

conda_envs = !conda env list
res = [i for i in conda_envs if 'test36' in i]
if (len(res) == 0):
    print('not found test36 env', len(res))
    !conda create -y -q --name test36 python=3.6 libarchive cartopy
else:
    print('found test36 env', len(res))
installing miniconda
--2020-06-28 10:59:43--  https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
Resolving repo.continuum.io (repo.continuum.io)... 104.18.200.79, 104.18.201.79, 2606:4700::6812:c84f, ...
Connecting to repo.continuum.io (repo.continuum.io)|104.18.200.79|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh [following]
--2020-06-28 10:59:43--  https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh
Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.131.3, 104.16.130.3, 2606:4700::6810:8203, ...
Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.131.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58468498 (56M) [application/x-sh]
Saving to: ‘Miniconda3-4.5.4-Linux-x86_64.sh’

Miniconda3-4.5.4-Li 100%[===================>]  55.76M   172MB/s    in 0.3s    

2020-06-28 10:59:43 (172 MB/s) - ‘Miniconda3-4.5.4-Linux-x86_64.sh’ saved [58468498/58468498]

PREFIX=/usr/local
installing: python-3.6.5-hc3d631a_2 ...
Python 3.6.5 :: Anaconda, Inc.
installing: ca-certificates-2018.03.07-0 ...
installing: conda-env-2.6.0-h36134e3_1 ...
installing: libgcc-ng-7.2.0-hdf63c60_3 ...
installing: libstdcxx-ng-7.2.0-hdf63c60_3 ...
installing: libffi-3.2.1-hd88cf55_4 ...
installing: ncurses-6.1-hf484d3e_0 ...
installing: openssl-1.0.2o-h20670df_0 ...
installing: tk-8.6.7-hc745277_3 ...
installing: xz-5.2.4-h14c3975_4 ...
installing: yaml-0.1.7-had09818_2 ...
installing: zlib-1.2.11-ha838bed_2 ...
installing: libedit-3.1.20170329-h6b74fdf_2 ...
installing: readline-7.0-ha6073c6_4 ...
installing: sqlite-3.23.1-he433501_0 ...
installing: asn1crypto-0.24.0-py36_0 ...
installing: certifi-2018.4.16-py36_0 ...
installing: chardet-3.0.4-py36h0f667ec_1 ...
installing: idna-2.6-py36h82fb2a8_1 ...
installing: pycosat-0.6.3-py36h0a5515d_0 ...
installing: pycparser-2.18-py36hf9f622e_1 ...
installing: pysocks-1.6.8-py36_0 ...
installing: ruamel_yaml-0.15.37-py36h14c3975_2 ...
installing: six-1.11.0-py36h372c433_1 ...
installing: cffi-1.11.5-py36h9745a5d_0 ...
installing: setuptools-39.2.0-py36_0 ...
installing: cryptography-2.2.2-py36h14c3975_0 ...
installing: wheel-0.31.1-py36_0 ...
installing: pip-10.0.1-py36_0 ...
installing: pyopenssl-18.0.0-py36_0 ...
installing: urllib3-1.22-py36hbe7ace6_0 ...
installing: requests-2.18.4-py36he2e5f8d_1 ...
installing: conda-4.5.4-py36_0 ...
installation finished.
WARNING:
    You currently have a PYTHONPATH environment variable set. This may cause
    unexpected behavior when running the Python interpreter in Miniconda3.
    For best results, please verify that your PYTHONPATH only points to
    directories of packages that are compatible with the Python interpreter
    in Miniconda3: /usr/local
Solving environment: ...working... done

## Package Plan ##

  environment location: /usr/local

  added / updated specs: 
    - conda


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    xz-5.2.5                   |       h7b6447c_0         438 KB
    urllib3-1.25.9             |             py_0          98 KB
    yaml-0.2.5                 |       h7b6447c_0          87 KB
    conda-package-handling-1.6.1|   py37h7b6447c_0         886 KB
    brotlipy-0.7.0             |py37h7b6447c_1000         348 KB
    pyopenssl-19.0.0           |           py37_0          82 KB
    libgcc-ng-9.1.0            |       hdf63c60_0         8.1 MB
    wheel-0.34.2               |           py37_0          49 KB
    pip-20.1.1                 |           py37_1         2.0 MB
    certifi-2020.6.20          |           py37_0         159 KB
    tk-8.6.10                  |       hbc83047_0         3.2 MB
    readline-7.0               |       h7b6447c_5         392 KB
    zlib-1.2.11                |       h7b6447c_3         120 KB
    libedit-3.1.20181209       |       hc058e9b_0         188 KB
    _libgcc_mutex-0.1          |             main           3 KB
    idna-2.9                   |             py_1          56 KB
    pycparser-2.20             |             py_0          93 KB
    openssl-1.0.2u             |       h7b6447c_0         3.1 MB
    sqlite-3.31.1              |       h7b6447c_0         2.0 MB
    pysocks-1.7.1              |           py37_0          30 KB
    cryptography-2.3.1         |   py37hc365091_0         585 KB
    pycosat-0.6.3              |   py37h7b6447c_0         107 KB
    conda-4.8.3                |           py37_0         3.0 MB
    ruamel_yaml-0.15.87        |   py37h7b6447c_1         253 KB
    cffi-1.14.0                |   py37h2e261b9_0         225 KB
    ca-certificates-2020.1.1   |                0         132 KB
    six-1.15.0                 |             py_0          13 KB
    setuptools-47.3.1          |           py37_0         647 KB
    tqdm-4.46.1                |             py_0          60 KB
    asn1crypto-1.3.0           |           py37_0         162 KB
    chardet-3.0.4              |        py37_1003         173 KB
    requests-2.24.0            |             py_0          54 KB
    python-3.7.0               |       hc3d631a_0        31.7 MB
    ------------------------------------------------------------
                                           Total:        58.5 MB

The following NEW packages will be INSTALLED:

    _libgcc_mutex:          0.1-main               
    brotlipy:               0.7.0-py37h7b6447c_1000
    conda-package-handling: 1.6.1-py37h7b6447c_0   
    tqdm:                   4.46.1-py_0            

The following packages will be UPDATED:

    asn1crypto:             0.24.0-py36_0           --> 1.3.0-py37_0           
    ca-certificates:        2018.03.07-0            --> 2020.1.1-0             
    certifi:                2018.4.16-py36_0        --> 2020.6.20-py37_0       
    cffi:                   1.11.5-py36h9745a5d_0   --> 1.14.0-py37h2e261b9_0  
    chardet:                3.0.4-py36h0f667ec_1    --> 3.0.4-py37_1003        
    conda:                  4.5.4-py36_0            --> 4.8.3-py37_0           
    cryptography:           2.2.2-py36h14c3975_0    --> 2.3.1-py37hc365091_0   
    idna:                   2.6-py36h82fb2a8_1      --> 2.9-py_1               
    libedit:                3.1.20170329-h6b74fdf_2 --> 3.1.20181209-hc058e9b_0
    libgcc-ng:              7.2.0-hdf63c60_3        --> 9.1.0-hdf63c60_0       
    openssl:                1.0.2o-h20670df_0       --> 1.0.2u-h7b6447c_0      
    pip:                    10.0.1-py36_0           --> 20.1.1-py37_1          
    pycosat:                0.6.3-py36h0a5515d_0    --> 0.6.3-py37h7b6447c_0   
    pycparser:              2.18-py36hf9f622e_1     --> 2.20-py_0              
    pyopenssl:              18.0.0-py36_0           --> 19.0.0-py37_0          
    pysocks:                1.6.8-py36_0            --> 1.7.1-py37_0           
    python:                 3.6.5-hc3d631a_2        --> 3.7.0-hc3d631a_0       
    readline:               7.0-ha6073c6_4          --> 7.0-h7b6447c_5         
    requests:               2.18.4-py36he2e5f8d_1   --> 2.24.0-py_0            
    ruamel_yaml:            0.15.37-py36h14c3975_2  --> 0.15.87-py37h7b6447c_1 
    setuptools:             39.2.0-py36_0           --> 47.3.1-py37_0          
    six:                    1.11.0-py36h372c433_1   --> 1.15.0-py_0            
    sqlite:                 3.23.1-he433501_0       --> 3.31.1-h7b6447c_0      
    tk:                     8.6.7-hc745277_3        --> 8.6.10-hbc83047_0      
    urllib3:                1.22-py36hbe7ace6_0     --> 1.25.9-py_0            
    wheel:                  0.31.1-py36_0           --> 0.34.2-py37_0          
    xz:                     5.2.4-h14c3975_4        --> 5.2.5-h7b6447c_0       
    yaml:                   0.1.7-had09818_2        --> 0.2.5-h7b6447c_0       
    zlib:                   1.2.11-ha838bed_2       --> 1.2.11-h7b6447c_3      

Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
no change     /usr/local/condabin/conda
no change     /usr/local/bin/conda
no change     /usr/local/bin/conda-env
no change     /usr/local/bin/activate
no change     /usr/local/bin/deactivate
no change     /usr/local/etc/profile.d/conda.sh
no change     /usr/local/etc/fish/conf.d/conda.fish
no change     /usr/local/shell/condabin/Conda.psm1
no change     /usr/local/shell/condabin/conda-hook.ps1
no change     /usr/local/lib/python3.7/site-packages/xontrib/conda.xsh
no change     /usr/local/etc/profile.d/conda.csh
modified      /root/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - _license

Current channels:

  - https://repo.anaconda.com/pkgs/main/linux-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/linux-64
  - https://repo.anaconda.com/pkgs/r/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.


not found test36 env 0
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

## Package Plan ##

  environment location: /usr/local/envs/test36

  added / updated specs:
    - cartopy
    - libarchive
    - python=3.6


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _libgcc_mutex-0.1          |             main           3 KB
    blas-1.0                   |              mkl           6 KB
    brotlipy-0.7.0             |py36h7b6447c_1000         323 KB
    bzip2-1.0.8                |       h7b6447c_0          78 KB
    ca-certificates-2020.1.1   |                0         125 KB
    cartopy-0.17.0             |   py36h3e2e9bd_1         1.6 MB
    certifi-2020.6.20          |           py36_0         156 KB
    cffi-1.14.0                |   py36he30daa8_1         225 KB
    chardet-3.0.4              |        py36_1003         180 KB
    cryptography-2.9.2         |   py36h1ba5d50_0         556 KB
    cycler-0.10.0              |           py36_0          13 KB
    dbus-1.13.16               |       hb2f20db_0         501 KB
    expat-2.2.9                |       he6710b0_2         156 KB
    fontconfig-2.13.0          |       h9420a91_0         227 KB
    freetype-2.10.2            |       h5ab3b9f_0         608 KB
    geos-3.8.0                 |       he6710b0_0         961 KB
    glib-2.65.0                |       h3eb4bd4_0         2.9 MB
    gst-plugins-base-1.14.0    |       hbbd80ab_1         4.8 MB
    gstreamer-1.14.0           |       hb31296c_0         3.1 MB
    icu-58.2                   |       he6710b0_3        10.5 MB
    idna-2.9                   |             py_1          49 KB
    intel-openmp-2020.1        |              217         780 KB
    jpeg-9b                    |       h024ee3a_2         214 KB
    kiwisolver-1.2.0           |   py36hfd86e86_0          84 KB
    krb5-1.17.1                |       h173b8e3_0         1.3 MB
    ld_impl_linux-64-2.33.1    |       h53a641e_7         568 KB
    libarchive-3.4.2           |       h62408e4_0         796 KB
    libcurl-7.69.1             |       h20c2e04_0         431 KB
    libedit-3.1.20191231       |       h7b6447c_0         167 KB
    libffi-3.3                 |       he6710b0_1          50 KB
    libgcc-ng-9.1.0            |       hdf63c60_0         5.1 MB
    libgfortran-ng-7.3.0       |       hdf63c60_0        1006 KB
    libpng-1.6.37              |       hbc83047_0         278 KB
    libssh2-1.9.0              |       h1ba5d50_1         269 KB
    libstdcxx-ng-9.1.0         |       hdf63c60_0         3.1 MB
    libtiff-4.1.0              |       h2733197_1         449 KB
    libuuid-1.0.3              |       h1bed415_2          15 KB
    libxcb-1.13                |       h1bed415_1         421 KB
    libxml2-2.9.10             |       he19cac6_1         1.2 MB
    lz4-c-1.9.2                |       he6710b0_0         191 KB
    matplotlib-3.2.2           |                0          21 KB
    matplotlib-base-3.2.2      |   py36hef1b27d_0         5.4 MB
    mkl-2020.1                 |              217       129.0 MB
    mkl-service-2.3.0          |   py36he904b0f_0         219 KB
    mkl_fft-1.1.0              |   py36h23d657b_0         144 KB
    mkl_random-1.1.1           |   py36h0573a6f_0         327 KB
    ncurses-6.2                |       he6710b0_1         817 KB
    numpy-1.18.5               |   py36ha1c710e_0           5 KB
    numpy-base-1.18.5          |   py36hde5b4d6_0         4.1 MB
    olefile-0.46               |           py36_0          48 KB
    openssl-1.1.1g             |       h7b6447c_0         2.5 MB
    owslib-0.19.2              |             py_1         127 KB
    pcre-8.44                  |       he6710b0_0         212 KB
    pillow-7.1.2               |   py36hb39fc2d_0         604 KB
    pip-20.1.1                 |           py36_1         1.8 MB
    proj-7.0.1                 |       h59a7b90_1         2.7 MB
    pycparser-2.20             |             py_0          92 KB
    pyepsg-0.4.0               |           py36_0          26 KB
    pykdtree-1.3.1             |   py36hdd07704_2          61 KB
    pyopenssl-19.1.0           |           py36_0          87 KB
    pyparsing-2.4.7            |             py_0          65 KB
    pyproj-2.6.1.post1         |   py36h61f852b_1         389 KB
    pyqt-5.9.2                 |   py36h05f1152_2         4.5 MB
    pyshp-2.1.0                |             py_0          35 KB
    pysocks-1.7.1              |           py36_0          30 KB
    python-3.6.10              |       h7579374_2        29.7 MB
    python-dateutil-2.8.1      |             py_0         215 KB
    pytz-2020.1                |             py_0         184 KB
    pyyaml-5.3.1               |   py36h7b6447c_1         180 KB
    qt-5.9.7                   |       h5867ecd_1        68.5 MB
    readline-8.0               |       h7b6447c_0         356 KB
    requests-2.24.0            |             py_0          56 KB
    scipy-1.5.0                |   py36h0b6359f_0        14.4 MB
    setuptools-47.3.1          |           py36_0         514 KB
    shapely-1.7.0              |   py36h98ec03d_0         394 KB
    sip-4.19.8                 |   py36hf484d3e_0         274 KB
    six-1.15.0                 |             py_0          13 KB
    sqlite-3.32.3              |       h62c20be_0         1.1 MB
    tk-8.6.10                  |       hbc83047_0         3.0 MB
    tornado-6.0.4              |   py36h7b6447c_1         597 KB
    urllib3-1.25.9             |             py_0         103 KB
    wheel-0.34.2               |           py36_0          51 KB
    xz-5.2.5                   |       h7b6447c_0         341 KB
    yaml-0.2.5                 |       h7b6447c_0          75 KB
    zlib-1.2.11                |       h7b6447c_3         103 KB
    zstd-1.4.4                 |       h0b5b093_3         447 KB
    ------------------------------------------------------------
                                           Total:       316.8 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
  blas               pkgs/main/linux-64::blas-1.0-mkl
  brotlipy           pkgs/main/linux-64::brotlipy-0.7.0-py36h7b6447c_1000
  bzip2              pkgs/main/linux-64::bzip2-1.0.8-h7b6447c_0
  ca-certificates    pkgs/main/linux-64::ca-certificates-2020.1.1-0
  cartopy            pkgs/main/linux-64::cartopy-0.17.0-py36h3e2e9bd_1
  certifi            pkgs/main/linux-64::certifi-2020.6.20-py36_0
  cffi               pkgs/main/linux-64::cffi-1.14.0-py36he30daa8_1
  chardet            pkgs/main/linux-64::chardet-3.0.4-py36_1003
  cryptography       pkgs/main/linux-64::cryptography-2.9.2-py36h1ba5d50_0
  cycler             pkgs/main/linux-64::cycler-0.10.0-py36_0
  dbus               pkgs/main/linux-64::dbus-1.13.16-hb2f20db_0
  expat              pkgs/main/linux-64::expat-2.2.9-he6710b0_2
  fontconfig         pkgs/main/linux-64::fontconfig-2.13.0-h9420a91_0
  freetype           pkgs/main/linux-64::freetype-2.10.2-h5ab3b9f_0
  geos               pkgs/main/linux-64::geos-3.8.0-he6710b0_0
  glib               pkgs/main/linux-64::glib-2.65.0-h3eb4bd4_0
  gst-plugins-base   pkgs/main/linux-64::gst-plugins-base-1.14.0-hbbd80ab_1
  gstreamer          pkgs/main/linux-64::gstreamer-1.14.0-hb31296c_0
  icu                pkgs/main/linux-64::icu-58.2-he6710b0_3
  idna               pkgs/main/noarch::idna-2.9-py_1
  intel-openmp       pkgs/main/linux-64::intel-openmp-2020.1-217
  jpeg               pkgs/main/linux-64::jpeg-9b-h024ee3a_2
  kiwisolver         pkgs/main/linux-64::kiwisolver-1.2.0-py36hfd86e86_0
  krb5               pkgs/main/linux-64::krb5-1.17.1-h173b8e3_0
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.33.1-h53a641e_7
  libarchive         pkgs/main/linux-64::libarchive-3.4.2-h62408e4_0
  libcurl            pkgs/main/linux-64::libcurl-7.69.1-h20c2e04_0
  libedit            pkgs/main/linux-64::libedit-3.1.20191231-h7b6447c_0
  libffi             pkgs/main/linux-64::libffi-3.3-he6710b0_1
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-9.1.0-hdf63c60_0
  libgfortran-ng     pkgs/main/linux-64::libgfortran-ng-7.3.0-hdf63c60_0
  libpng             pkgs/main/linux-64::libpng-1.6.37-hbc83047_0
  libssh2            pkgs/main/linux-64::libssh2-1.9.0-h1ba5d50_1
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-9.1.0-hdf63c60_0
  libtiff            pkgs/main/linux-64::libtiff-4.1.0-h2733197_1
  libuuid            pkgs/main/linux-64::libuuid-1.0.3-h1bed415_2
  libxcb             pkgs/main/linux-64::libxcb-1.13-h1bed415_1
  libxml2            pkgs/main/linux-64::libxml2-2.9.10-he19cac6_1
  lz4-c              pkgs/main/linux-64::lz4-c-1.9.2-he6710b0_0
  matplotlib         pkgs/main/linux-64::matplotlib-3.2.2-0
  matplotlib-base    pkgs/main/linux-64::matplotlib-base-3.2.2-py36hef1b27d_0
  mkl                pkgs/main/linux-64::mkl-2020.1-217
  mkl-service        pkgs/main/linux-64::mkl-service-2.3.0-py36he904b0f_0
  mkl_fft            pkgs/main/linux-64::mkl_fft-1.1.0-py36h23d657b_0
  mkl_random         pkgs/main/linux-64::mkl_random-1.1.1-py36h0573a6f_0
  ncurses            pkgs/main/linux-64::ncurses-6.2-he6710b0_1
  numpy              pkgs/main/linux-64::numpy-1.18.5-py36ha1c710e_0
  numpy-base         pkgs/main/linux-64::numpy-base-1.18.5-py36hde5b4d6_0
  olefile            pkgs/main/linux-64::olefile-0.46-py36_0
  openssl            pkgs/main/linux-64::openssl-1.1.1g-h7b6447c_0
  owslib             pkgs/main/noarch::owslib-0.19.2-py_1
  pcre               pkgs/main/linux-64::pcre-8.44-he6710b0_0
  pillow             pkgs/main/linux-64::pillow-7.1.2-py36hb39fc2d_0
  pip                pkgs/main/linux-64::pip-20.1.1-py36_1
  proj               pkgs/main/linux-64::proj-7.0.1-h59a7b90_1
  pycparser          pkgs/main/noarch::pycparser-2.20-py_0
  pyepsg             pkgs/main/linux-64::pyepsg-0.4.0-py36_0
  pykdtree           pkgs/main/linux-64::pykdtree-1.3.1-py36hdd07704_2
  pyopenssl          pkgs/main/linux-64::pyopenssl-19.1.0-py36_0
  pyparsing          pkgs/main/noarch::pyparsing-2.4.7-py_0
  pyproj             pkgs/main/linux-64::pyproj-2.6.1.post1-py36h61f852b_1
  pyqt               pkgs/main/linux-64::pyqt-5.9.2-py36h05f1152_2
  pyshp              pkgs/main/noarch::pyshp-2.1.0-py_0
  pysocks            pkgs/main/linux-64::pysocks-1.7.1-py36_0
  python             pkgs/main/linux-64::python-3.6.10-h7579374_2
  python-dateutil    pkgs/main/noarch::python-dateutil-2.8.1-py_0
  pytz               pkgs/main/noarch::pytz-2020.1-py_0
  pyyaml             pkgs/main/linux-64::pyyaml-5.3.1-py36h7b6447c_1
  qt                 pkgs/main/linux-64::qt-5.9.7-h5867ecd_1
  readline           pkgs/main/linux-64::readline-8.0-h7b6447c_0
  requests           pkgs/main/noarch::requests-2.24.0-py_0
  scipy              pkgs/main/linux-64::scipy-1.5.0-py36h0b6359f_0
  setuptools         pkgs/main/linux-64::setuptools-47.3.1-py36_0
  shapely            pkgs/main/linux-64::shapely-1.7.0-py36h98ec03d_0
  sip                pkgs/main/linux-64::sip-4.19.8-py36hf484d3e_0
  six                pkgs/main/noarch::six-1.15.0-py_0
  sqlite             pkgs/main/linux-64::sqlite-3.32.3-h62c20be_0
  tk                 pkgs/main/linux-64::tk-8.6.10-hbc83047_0
  tornado            pkgs/main/linux-64::tornado-6.0.4-py36h7b6447c_1
  urllib3            pkgs/main/noarch::urllib3-1.25.9-py_0
  wheel              pkgs/main/linux-64::wheel-0.34.2-py36_0
  xz                 pkgs/main/linux-64::xz-5.2.5-h7b6447c_0
  yaml               pkgs/main/linux-64::yaml-0.2.5-h7b6447c_0
  zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3
  zstd               pkgs/main/linux-64::zstd-1.4.4-h0b5b093_3


Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done

You should see a lot of install activity above, similar to this:

installing miniconda --2020-06-27 22:45:59-- https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh Resolving repo.continuum.io (repo.continuum.io)... 104.18.201.79, 104.18.200.79, 2606:4700::6812:c94f, ... Connecting to repo.continuum.io (repo.continuum.io)|104.18.201.79|:443... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh [following] --2020-06-27 22:45:59-- https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.131.3, 104.16.130.3, 2606:4700::6810:8203, ... Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.131.3|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 58468498 (56M) [application/x-sh] Saving to: ‘Miniconda3-4.5.4-Linux-x86_64.sh.1’

Miniconda3-4.5.4-Li 100%[===================>] 55.76M 180MB/s in 0.3s

2020-06-27 22:45:59 (180 MB/s) - ‘Miniconda3-4.5.4-Linux-x86_64.sh.1’ saved [58468498/58468498]

PREFIX=/usr/local installing: python-3.6.5-hc3d631a_2 ... Python 3.6.5 :: Anaconda, Inc. installing: ca-certificates-2018.03.07-0 ... ... unlinking: zlib-1.2.11-h7b6447c_3 installation finished. WARNING: You currently have a PYTHONPATH environment variable set. This may cause unexpected behavior when running the Python interpreter in Miniconda3. For best results, please verify that your PYTHONPATH only points to directories of packages that are compatible with the Python interpreter in Miniconda3: /usr/local Solving environment: ...working... done

Package Plan

environment location: /usr/local

added / updated specs:

- conda


The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
openssl-1.1.1g             |       h7b6447c_0         3.8 MB

...

conda-package-handling-1.6.1|   py36h7b6447c_0         886 KB
------------------------------------------------------------
                                       Total:        48.8 MB

The following NEW packages will be INSTALLED:

conda-package-handling: 1.6.1-py36h7b6447c_0
tqdm:                   4.46.1-py_0         

The following packages will be UPDATED:

ca-certificates:        2018.03.07-0         --> 2020.1.1-0          

... tk: 8.6.7-hc745277_3 --> 8.6.10-hbc83047_0

Preparing transaction: ...working... done Verifying transaction: ...working... done Executing transaction: ...working... done no change /usr/local/condabin/conda ... no change /usr/local/etc/profile.d/conda.csh modified /root/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve. Collecting package metadata (repodata.json): ...working... done Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  • _license

Current channels:

To search for alternate channels that may provide the conda package you're looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

not found test36 env 0 Collecting package metadata (current_repodata.json): ...working... done Solving environment: ...working... done

Package Plan

environment location: /usr/local/envs/test36

added / updated specs:

- python=3.6


The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
_libgcc_mutex-0.1          |             main           3 KB

...

zlib-1.2.11                |       h7b6447c_3         103 KB
------------------------------------------------------------
                                       Total:        49.4 MB

The following NEW packages will be INSTALLED:

_libgcc_mutex pkgs/main/linux-64::_libgcc_mutex-0.1-main ... zlib pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3

Preparing transaction: ...working... done Verifying transaction: ...working... done Executing transaction: ...working... done

check if conda exists again, now you should see something like "/usr/loca/bin/conda"

In [ ]:
!which conda
/usr/local/bin/conda

Check on your environment

In [ ]:
!env
CUDNN_VERSION=7.6.5.32
LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
CLOUDSDK_PYTHON=python3
_=/usr/bin/env
LANG=en_US.UTF-8
HOSTNAME=1a6abc06fc9c
OLDPWD=/
CLOUDSDK_CONFIG=/content/.config
NVIDIA_VISIBLE_DEVICES=all
DATALAB_SETTINGS_OVERRIDES={"kernelManagerProxyPort":6000,"kernelManagerProxyHost":"172.28.0.3","jupyterArgs":["--ip=\"172.28.0.2\""]}
ENV=/root/.bashrc
PAGER=cat
NCCL_VERSION=2.4.8
TF_FORCE_GPU_ALLOW_GROWTH=true
JPY_PARENT_PID=18
NO_GCE_CHECK=True
PWD=/content
HOME=/root
LAST_FORCED_REBUILD=20200609
CLICOLOR=1
DEBIAN_FRONTEND=noninteractive
LIBRARY_PATH=/usr/local/cuda/lib64/stubs
GCE_METADATA_TIMEOUT=0
GLIBCPP_FORCE_NEW=1
TBE_CREDS_ADDR=172.28.0.1:8008
TERM=xterm-color
SHELL=/bin/bash
GCS_READ_CACHE_BLOCK_SIZE_MB=16
PYTHONWARNINGS=ignore:::pip._internal.cli.base_command
MPLBACKEND=module://ipykernel.pylab.backend_inline
CUDA_PKG_VERSION=10-1=10.1.243-1
CUDA_VERSION=10.1.243
NVIDIA_DRIVER_CAPABILITIES=compute,utility
SHLVL=2
PYTHONPATH=/env/python
NVIDIA_REQUIRE_CUDA=cuda>=10.1 brand=tesla,driver>=384,driver<385 brand=tesla,driver>=396,driver<397 brand=tesla,driver>=410,driver<411
COLAB_GPU=0
GLIBCXX_FORCE_NEW=1
PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4
GIT_PAGER=cat

If everything looks like I am showing, with no errors, you can run python code in your new conda environment. However, this will only persist for one cell. Then next cell will revert back to your base Google Colab environment. This is because you are using %%bash, this command will open a shell and run the commands within the same cell, but will close down when you exit the cell. You can test if the correct environment is active using conda env list and conda list. I can see my new environment is active (*) and the new package cartopy is available now.

In [ ]:
%%bash
source activate test36
conda env list
conda list
python
import sys
import cartopy
#import libarchive
# maybe only need this the first time we run this notebook
sys.path.append('/usr/local/lib/python3.6/site-packages')

print("Python version")
print(sys.version)
# conda environments:
#
base                     /usr/local
test36                *  /usr/local/envs/test36

# packages in environment at /usr/local/envs/test36:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
blas                      1.0                         mkl  
brotlipy                  0.7.0           py36h7b6447c_1000  
bzip2                     1.0.8                h7b6447c_0  
ca-certificates           2020.1.1                      0  
cartopy                   0.17.0           py36h3e2e9bd_1  
certifi                   2020.6.20                py36_0  
cffi                      1.14.0           py36he30daa8_1  
chardet                   3.0.4                 py36_1003  
cryptography              2.9.2            py36h1ba5d50_0  
cycler                    0.10.0                   py36_0  
dbus                      1.13.16              hb2f20db_0  
expat                     2.2.9                he6710b0_2  
fontconfig                2.13.0               h9420a91_0  
freetype                  2.10.2               h5ab3b9f_0  
geos                      3.8.0                he6710b0_0  
glib                      2.65.0               h3eb4bd4_0  
gst-plugins-base          1.14.0               hbbd80ab_1  
gstreamer                 1.14.0               hb31296c_0  
icu                       58.2                 he6710b0_3  
idna                      2.9                        py_1  
intel-openmp              2020.1                      217  
jpeg                      9b                   h024ee3a_2  
kiwisolver                1.2.0            py36hfd86e86_0  
krb5                      1.17.1               h173b8e3_0  
ld_impl_linux-64          2.33.1               h53a641e_7  
libarchive                3.4.2                h62408e4_0  
libcurl                   7.69.1               h20c2e04_0  
libedit                   3.1.20191231         h7b6447c_0  
libffi                    3.3                  he6710b0_1  
libgcc-ng                 9.1.0                hdf63c60_0  
libgfortran-ng            7.3.0                hdf63c60_0  
libpng                    1.6.37               hbc83047_0  
libssh2                   1.9.0                h1ba5d50_1  
libstdcxx-ng              9.1.0                hdf63c60_0  
libtiff                   4.1.0                h2733197_1  
libuuid                   1.0.3                h1bed415_2  
libxcb                    1.13                 h1bed415_1  
libxml2                   2.9.10               he19cac6_1  
lz4-c                     1.9.2                he6710b0_0  
matplotlib                3.2.2                         0  
matplotlib-base           3.2.2            py36hef1b27d_0  
mkl                       2020.1                      217  
mkl-service               2.3.0            py36he904b0f_0  
mkl_fft                   1.1.0            py36h23d657b_0  
mkl_random                1.1.1            py36h0573a6f_0  
ncurses                   6.2                  he6710b0_1  
numpy                     1.18.5           py36ha1c710e_0  
numpy-base                1.18.5           py36hde5b4d6_0  
olefile                   0.46                     py36_0  
openssl                   1.1.1g               h7b6447c_0  
owslib                    0.19.2                     py_1  
pcre                      8.44                 he6710b0_0  
pillow                    7.1.2            py36hb39fc2d_0  
pip                       20.1.1                   py36_1  
proj                      7.0.1                h59a7b90_1  
pycparser                 2.20                       py_0  
pyepsg                    0.4.0                    py36_0  
pykdtree                  1.3.1            py36hdd07704_2  
pyopenssl                 19.1.0                   py36_0  
pyparsing                 2.4.7                      py_0  
pyproj                    2.6.1.post1      py36h61f852b_1  
pyqt                      5.9.2            py36h05f1152_2  
pyshp                     2.1.0                      py_0  
pysocks                   1.7.1                    py36_0  
python                    3.6.10               h7579374_2  
python-dateutil           2.8.1                      py_0  
pytz                      2020.1                     py_0  
pyyaml                    5.3.1            py36h7b6447c_1  
qt                        5.9.7                h5867ecd_1  
readline                  8.0                  h7b6447c_0  
requests                  2.24.0                     py_0  
scipy                     1.5.0            py36h0b6359f_0  
setuptools                47.3.1                   py36_0  
shapely                   1.7.0            py36h98ec03d_0  
sip                       4.19.8           py36hf484d3e_0  
six                       1.15.0                     py_0  
sqlite                    3.32.3               h62c20be_0  
tk                        8.6.10               hbc83047_0  
tornado                   6.0.4            py36h7b6447c_1  
urllib3                   1.25.9                     py_0  
wheel                     0.34.2                   py36_0  
xz                        5.2.5                h7b6447c_0  
yaml                      0.2.5                h7b6447c_0  
zlib                      1.2.11               h7b6447c_3  
zstd                      1.4.4                h0b5b093_3  
Python version
3.6.10 |Anaconda, Inc.| (default, May  8 2020, 02:54:21) 
[GCC 7.3.0]

The next cell will revert back to the default shell that was opened when you started Google Colab

In [ ]:
import sys
print(sys.version)
3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0]

Not sure how to get around this, and run multiple cells from within your own environment only invoking python once...

Also note that conda activate does not work. Only source activate works like this so far. Still looking at this option, but the hints in this error do not help.

In [ ]:
%%bash
conda activate test36

python
import sys
# maybe only need this the first time we run this notebook
sys.path.append('/usr/local/lib/python3.6/site-packages')

print("Python version")
print(sys.version)
# conda environments:
#
base                  *  /usr/local
test36                   /usr/local/envs/test36

Python version
3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0]
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


Additional info about the conda you just installed

In [ ]:
!conda info
     active environment : None
       user config file : /root/.condarc
 populated config files : 
          conda version : 4.8.3
    conda-build version : not installed
         python version : 3.6.8.final.0
       virtual packages : __glibc=2.27
       base environment : /usr/local  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /usr/local/pkgs
                          /root/.conda/pkgs
       envs directories : /usr/local/envs
                          /root/.conda/envs
               platform : linux-64
             user-agent : conda/4.8.3 requests/2.18.4 CPython/3.6.8 Linux/4.19.104+ ubuntu/18.04.3 glibc/2.27
                UID:GID : 0:0
             netrc file : None
           offline mode : False

Location of your environment inside this container

In [ ]:
!ls -rlt  /usr/local/envs
total 4
drwxr-xr-x 10 root root 4096 Jun 27 22:47 test36
In [ ]: