如何在Google Colaboratory中安装第三方模块

2024-06-16 14:17:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要使用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的情况下安装模块时,它给了我权限错误

步骤1:安装谷歌硬盘

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

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

步骤2:将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

步骤4:问题:如何安装模块

如何在GoogleColab中安装CFITSIO模块并进行编译


Tags: 模块importmakeenableconfiguregooglesyssudo