无法在Google Colab中安装自定义软件包

时间:2020-02-25 22:01:03

标签: python jupyter-notebook google-colaboratory python-packaging

我有一个自己编写的自定义程序包,称为deblurrer,它是一堆用于训练神经网络的脚本。

在Google Colab中,我成功克隆了我的存储库,我拥有执行setup.py模块并安装deblurrer 1.0.0所需的所有东西。当我在PC上本地安装deblurrer时,一切都按预期方式工作,但是当我尝试在Colab中运行!python setup.py install时,没有安装任何东西,实际上,输出显示一切都很好,但是我无法导入该软件包。在两个独立的Colab单元中执行下一个代码以重现该问题:

# Cell 01
# Executes the cell in bash mode
%%bash

git clone https://github.com/ElPapi42/deep-deblurring
python deep-deblurring/setup.py install
# Cell 02
import deblurrer

如您所见,安装按预期运行,但是在导入时:ModuleNotFoundError: No module named 'deblurrer'

有什么问题吗?

1 个答案:

答案 0 :(得分:3)

您必须对Colab采用稍微不同的方法。

# 1. Download the repo and set it as the current directory
!git clone https://github.com/ElPapi42/deep-deblurring
%cd deep-deblurring

# 2. install the project/module
!python setup.py install

# 3. Add the project directory to the path
import os, sys
sys.path.append(os.getcwd())

#4. Run your code
# ....

如此处https://stackoverflow.com/a/53747334/2466781

所述
相关问题