3

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

cjds
  • 8,268
  • 10
  • 49
  • 84

1 Answers1

2

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'
korakot
  • 37,818
  • 16
  • 123
  • 144
  • 1
    I am trying to set LD_LIBRARY_PATH with statement you have mentioned. It shows up in the env variables list ( checked from !printenv), but in my software, when I am accessing .so library which placed at LD_LIBRARY_PATH, it is not able to find it.. it works on the regular machine, but not on google code colab. Can you please help to identify what I am missing? Thank you. – Vinay Aug 16 '20 at 20:23