【问题标题】:How to make persistent installation with Colaboratory?如何使用 Colaboratory 进行持久安装?
【发布时间】:2019-12-08 20:22:39
【问题描述】:

有没有办法在您从 Colaboratory Environment 启动笔记本时获得的机器上进行持久安装?

mybinder.org 有一个这样的机制,它带有一个 requirements.txt 或 setup.py,可以在启动时指定你想要的不同包。 https://mybinder.readthedocs.io/en/latest/config_files.html#requirements-txt-install-a-python-environment

我已经使用安装过程测试了 colab 笔记本,但每次我想工作时都必须重新运行一系列单元格。 尝试: https://colab.research.google.com/drive/1u5Y-92-b4rVcJjkUpPPa5xnuvKAHcnNa

另外如何定义一次环境变量(在启动时)? 我是否还必须每次都重新运行他们的设置?

谢谢 帕特里克

【问题讨论】:

    标签: google-colaboratory


    【解决方案1】:

    这是我永久安装库 jdc 的方法,方法是在 Google 云端硬盘中安装它。

    import os, sys
    from google.colab import drive
    drive.mount('/content/mnt')
    nb_path = '/content/notebooks'
    os.symlink('/content/mnt/My Drive/Colab Notebooks', nb_path)
    sys.path.insert(0, nb_path)
    
    # call this one time only
    !pip install --target=$nb_path jdc
    # later just import it
    import jdc   # for %%add_to
    

    这里是设置环境变量的方法。

    %env VAR1=value1
    %env VAR2=value2
    

    将它们放在您的第一个单元格中并运行它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 2018-04-21
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多