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

ElP*_*i42 5 python jupyter-notebook python-packaging google-colaboratory

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

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

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

git clone https://github.com/ElPapi42/deep-deblurring
python deep-deblurring/setup.py install
Run Code Online (Sandbox Code Playgroud)
# Cell 02
import deblurrer
Run Code Online (Sandbox Code Playgroud)

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

有什么问题吗?

Sil*_*one 6

您必须对 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
# ....
Run Code Online (Sandbox Code Playgroud)

如此处所述/sf/answers/3762313411/