Is it possible to set environment variables in Google's Colaboratory?

后端 未结 2 1463
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 04:20

I am running some Python scripts in Google\'s Colaboratory platform. Now, I need to set some environment variables of the system. Like the following shows:

!         


        
相关标签:
2条回答
  • 2020-12-18 04:36

    For PATH environment variables, such as PYTHONPATH, I use sys.path.insert or sys.path.append.

    You have these 2 options because sys.path is a list of strings (paths), thus you can either insert or append more strings.

    For example,

    If you want to insert a new path at index 0:

    import sys
    sys.path.insert(0,'/path/to/folder')
    

    If you want to append a new path:

    import sys
    sys.path.append('/path/to/folder')
    
    0 讨论(0)
  • 2020-12-18 04:46

    I normally set the PATH with os.environ, like this:

    import os
    os.environ['PATH'] += ":/usr/local/go/bin"
    
    0 讨论(0)
提交回复
热议问题