简体   繁体   中英

how to install python libraries upon creation of ai platform notebooks

I want to use "Select a script to run after creation" when I create a notebook instance in GCP.

Specifically, I want to use it to install python packages.

What kind of script (extension and contents) do I need to write?

This will be an example of Post startup script that installs Voila. Save this file in a GCS bucket and when creating the Notebook, define the path, for example:

gcloud notebooks instances create nb-1 \
'--vm-image-project=deeplearning-platform-release' \
'--vm-image-family=tf2-latest-cpu' \
'--metadata=post-startup-script=gs://ai-platform-notebooks-tools/install-voila.sh' \
'--location=us-central1-a'

Script contents:

#!/bin/bash -eu
# Installs Voila in AI Platform Notebook

function install_voila() {
  echo 'Installing voila...'
  /opt/conda/condabin/conda install -y -c conda-forge ipywidgets ipyvolume bqplot scipy
  /opt/conda/condabin/conda install -y -c conda-forge voila
  /opt/conda/bin/jupyter lab build
  systemctl restart jupyter.service || echo 'Error restarting jupyter.service.'
}

function download_samples() {
  echo 'Downloading samples...'
  cd /home/jupyter
  git clone https://github.com/voila-dashboards/voila

}

function main() {
  install_voila || echo 'Error installing voila.' 
  download_samples || echo 'Error downloading voila samples.' 
}

main

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM