cjds
cjds

Reputation: 8426

Set permanent environment variables in Google Colab

How do you set environment variables in Colab that persist after a runtime restart?

I have tried:

  1. Changing ~/.bashrc
!echo "LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/opt/ros/melodic/lib" >> /etc/environment

  1. Adding line to /etc/environment
!echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

Questions that don't have the answer:

Setting environment variables in Google Colab : All methods listed here do not persist after runtime restart

Upvotes: 3

Views: 4103

Answers (1)

korakot
korakot

Reputation: 40888

You can make it permanent, even after restart.

Just write a startup file. It will be run everytime jupyter restart. (but not if factory reset)

%%file /root/.ipython/profile_default/startup/startup.py
import os
os.environ['LD_LIBRARY_PATH']='/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/opt/ros/melodic/lib'

Upvotes: 2

Related Questions