[英]Using custom packages on Google-Colaboratory
I'm trying to use my custom package on Google Colaboratory and I'm facing some weird errors while doing that. 我正在尝试在Google Colaboratory上使用我的自定义程序包,而这样做时遇到了一些奇怪的错误。 Note that the package I'm trying to use works without any error on my computer/s. 请注意,我尝试使用的软件包在我的计算机上没有任何错误。
It is a Python 3.6 package called rohan
. 这是一个名为rohan
的Python 3.6软件包。 It is very basic in terms of functionalities. 就功能而言,这是非常基本的。
At first I installed it through pip command ( pip install rohan
). 首先,我通过pip命令安装了它( pip install rohan
)。 But I got a ModuleNotFoundError
error. 但是我收到了ModuleNotFoundError
错误。
import rohan
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-9046ed7b4857> in <module>()
----> 1 import rohan
ModuleNotFoundError: No module named 'rohan'
Then I installed it from the source. 然后我从源代码安装了它。
%%bash
git clone https://github.com/rraadd88/rohan.git
cd rohan
pip install -e .
This time, I could import the main module without any error ( import rohan
). 这次,我可以导入主模块而没有任何错误( import rohan
)。 However if I try to import submodule ( dandage
), I get an ImportError
. 但是,如果我尝试导入子模块( dandage
), dandage
收到ImportError
。
from rohan import dandage
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-6ea35256170e> in <module>()
----> 1 from rohan import dandage
ImportError: cannot import name 'dandage'
To me, the structure of the the package looks ok. 对我来说,包装的结构看起来还不错。
rohan
├── MANIFEST.in
├── rohan
│ ├── dandage
│ │ ├── subsubmodule
│ │ │ ├── script.py
│ │ │ └── __init__.py
| | ├── script.py
| | └── __init__.py
| ├── script.py
│ └── __init__.py
├── setup.cfg
└── setup.py
Source: https://github.com/rraadd88/rohan 资料来源: https : //github.com/rraadd88/rohan
Also as I said, the package works very well on my computer/s. 就像我说的那样,该软件包在我的计算机上也能很好地工作。 So I'm not sure why I'm not able to use it on Colaboratory. 所以我不确定为什么不能在Colaboratory上使用它。
You'll need to add the directory where you cloned the repo to sys.path
. 您需要将克隆存储库的目录添加到sys.path
。 For example: 例如:
!git clone https://github.com/rraadd88/rohan.git
import sys
sys.path.append('/content/rohan')
from rohan import dandage
Here's a complete notebook: https://colab.research.google.com/drive/1LSC_HyfbuOlEn7pfZYAjiOSE1fp6uipl 这是完整的笔记本: https : //colab.research.google.com/drive/1LSC_HyfbuOlEn7pfZYAjiOSE1fp6uipl
when i use autokeras,i also meet the same problem: 当我使用autokeras时,我也遇到同样的问题:
ModuleNotFoundError Traceback (most recent call last) in () ----> 1 from autokeras.text.text_supervised import TextClassifier 在()----> 1中从autokeras.text.text_supervised import TextClassifier中的ModuleNotFoundError Traceback(最近一次调用最后一次)
ModuleNotFoundError: No module named 'autokeras.text' ModuleNotFoundError:没有名为“ autokeras.text”的模块
NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt. 注意:如果由于缺少软件包而导致导入失败,则可以使用!pip或!apt手动安装依赖项。
To view examples of installing some common dependencies, click the 要查看安装一些常见依赖项的示例,请单击
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.