【问题标题】:How to install a third party module in Google Colaboratory如何在 Google Colaboratory 中安装第三方模块
【发布时间】:2020-01-15 01:28:06
【问题描述】:

我需要在 Google colab 中使用 cfitsio 库编译一些 c 程序,在我的 mac 中我可以执行以下操作:

1. download the files and unzip it http://heasarc.gsfc.nasa.gov/fitsio/fitsio.html

2. 
sudo -H ./configure --enable-sse2 --prefix=/usr/local --enable-reentrant 
sudo -H make
sudo -H make install

但是,我不允许在 google colab 中使用 sudo(当然这是必需的行为)

当我尝试在没有 sudo 的情况下安装模块时,它给了我权限错误。

第一步:挂载谷歌驱动器

import sys
ENV_COLAB = 'google.colab' in sys.modules

if ENV_COLAB:
    ### mount google drive
    from google.colab import drive
    drive.mount('/content/drive')

step2: cd 到模块的路径

%%bash

cd "drive/My Drive/Colab Notebooks/Research/cfitsio-3.47"

./configure --user --enable-sse2 --enable-reentrant

# step3: module installation fails
 bash: ./configure: /bin/sh: bad interpreter: Permission denied

step4: 问:如何安装模块?

如何在Google colab中安装CFITSIO模块并编译?

【问题讨论】:

  • 顺便说一句,即使在您的 Mac 中,您也不应该在编译代码时使用 sudo。这是危险且不必要的(如果出于某种原因看起来有必要,那么您的系统上配置错误)。

标签: python bash google-colaboratory fits


【解决方案1】:

不需要sudo。在 Colab 上,您已经以 root 身份运行。

这是一个完整的示例笔记本:

https://colab.research.google.com/drive/1RqtDwzhL8vWEJ-3ruGUGo-QckWr6gHUJ

【讨论】:

  • 非常感谢,我会尝试将编译后的模块复制到我的谷歌驱动器并使用适当的库链接从那里安装它,即使这不起作用,我每次都可以下载并编译模块如上例所示。
猜你喜欢
  • 2019-08-23
  • 2018-07-21
  • 1970-01-01
  • 2018-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-23
  • 2018-06-06
相关资源
最近更新 更多