'How to run jupyter lab in a conda environment on a google compute engine (Deep Learning VM)?

  • I made a conda environment in my Deep Learning VM. When I ssh to it (clicking SSH button of my instance in the VM instances page) and type source activate <environment_name> it gets activated correctly in the shell.

  • I successfully connect to jupyter lab from my local machine as explained from the docs

How can I use jupyter in a specific conda environment on this VM ?

The accepted way to run jupyter in a specific conda environment seems to be

Activate a conda environment in your terminal using source activate <environment_name> before you run jupyter notebook.

but the Deep Learning VM docs say

A Jupyter Lab session is started when your Deep Learning VM instance is initialized

so that I cannot source activate before the creation of the jupyter lab session.

Any ideas ?

  • run a standard jupyter notebook myself instead of using the jupyter lab provided by the VM ?
  • activate the environment in startup scripts of the VM before the creation of the jupyter lab ?


Solution 1:[1]

Please try out the below steps:

  1. source activate < env_name >

  2. conda install ipykernel

  3. ipython kernel install --name < env_name > --user

After this, launch your python code from hub.colfaxresearch.com and select Kernel --> Change Kernel --> < env_name >

Solution 2:[2]

The only way we've found to make it see all your environments(conda and new python environments) is to run a new jupyter lab instance.

  • When connecting over SSH map the 8888 or any other port instead of 8080 gcloud compute ssh ... -L 8888:localhost:8888
  • After connecting run jupyter lab from console. The default port is 8888.

This is one of the ugliest issues I've seen with GCE so far!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mat
Solution 2 Serhiy