无法在 Google Colab 中安装自定义包
Cant install custom package in Google Colab
我有一个自己写的自定义包叫deblurrer,它是一堆训练神经网络的脚本。
在 Google Colab 中,我成功克隆了我的存储库,我拥有执行 setup.py 模块和安装 deblurrer 1.0.0 所需的所有东西。当我在我的电脑本地安装 deblurrer 时,一切都按预期工作,但是当我尝试在 Colab 中 运行 !python setup.py install
时,没有安装任何东西,事实上,输出显示一切正常,但我无法导入包裹。在两个单独的 Colab Cell 中执行下一个代码以重现问题:
# 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
如您所见,安装 运行s 是正确的,但是导入时:ModuleNotFoundError: No module named 'deblurrer'
有什么问题吗?
您必须对 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
# ....
如此处所述
我有一个自己写的自定义包叫deblurrer,它是一堆训练神经网络的脚本。
在 Google Colab 中,我成功克隆了我的存储库,我拥有执行 setup.py 模块和安装 deblurrer 1.0.0 所需的所有东西。当我在我的电脑本地安装 deblurrer 时,一切都按预期工作,但是当我尝试在 Colab 中 运行 !python setup.py install
时,没有安装任何东西,事实上,输出显示一切正常,但我无法导入包裹。在两个单独的 Colab Cell 中执行下一个代码以重现问题:
# 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
如您所见,安装 运行s 是正确的,但是导入时:ModuleNotFoundError: No module named 'deblurrer'
有什么问题吗?
您必须对 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
# ....
如此处所述