Skip to content

Instantly share code, notes, and snippets.

Last active October 20, 2020 08:18
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Run jupyter notebooks remotely using a custom python environment.
# - access a remote running jupyter notebooks, for example on a
# cluster, locally. These steps can be run from any directory on your local
# machine.
# Create a tunnel for notebook communication. The user and server credentials
# should be the same as you used to log in to the server for the ``
# script.
ssh -N -f -L localhost:8888:localhost:8890 <user>@<server>
# Open the notebook in browser. This step only works on a mac, so if you are
# using linux just open the web page in browser.
open "http://localhost:8888"
# - run jupyter notebooks remotely, for example on a cluster. These
# steps should be run from your project directory.
# Set up virtual environment. If python3 isn't available then use
# `ls /usr/bin/python*` to see available installations. If none are shown, use
# `module avail` to list modules, and you'll have to include
# `source <python version>` in a job submission script.
python3 -m venv venv
# Sourcing the environment should override your current python3 command.
# Alternatively the correct python can be directly accessed via
# `venv/bin/python3`.
source venv/bin/activate
# Optional: Install additional modules via a script. Alternatively `pip install
# --requirement <requirements.txt>` is a good option if you have a requirements
# file. This can be generated with `pip freeze > requirements.txt`
# venv/bin/pip install <module1> <module2> <...>
# Set up a local jupyter notebooks module in the project.
python3 -m ipykernel install --name venv --display-name venv --user
# Launch the notebook. Port 8890 is used so as not to interfere with any locally
# running notebooks.
jupyter notebook --no-browser --port=8890
Copy link

Ekrekr commented Aug 12, 2019 should be run before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment