【发布时间】:2022-01-10 15:13:25
【问题描述】:
我尝试从 github 导入 Python 包。我在 Google Colab 工作。
存储库位于以下网址https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp。
所以我使用下面的代码
!pip install --upgrade
!pip install -q git+git://github.com/microsoft/nlp-recipes/tree/master/utils_nlp
from utils_nlp import *
我也试过了
!pip install -q git+https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp
我看到了其他(工作)示例,其中 url 以 .git 结尾:
!pip install -q git+https://github.com/huggingface/transformers.git
于是我依次尝试
!pip install -q git+https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp.git
但我也注意到https://github.com/microsoft/nlp-recipes/tree/master/utils_nlp.git 加载到错误页面,而https://github.com/huggingface/transformers.git 加载到https://github.com/huggingface/transformers,这让我很吃惊。
我们如何在这里加载 Python 包?
编辑
我按照建议使用
pip install git+https://github.com/microsoft/nlp-recipes.git
然后
from utils_nlp import *
工作,但它没有成功导入子文件夹,当我这样做时失败
from utils_nlp.models.transformers.abstractive_summarization_bertsum \
import BertSumAbs, BertSumAbsProcessor
而utils_nlp 确实包含一个文件夹models,而该文件夹又包含transformers
错误堆栈如下
/usr/local/lib/python3.7/dist-packages/utils_nlp/models/transformers/abstractive_summarization_bertsum.py in <module>()
15 from torch.utils.data.distributed import DistributedSampler
16 from tqdm import tqdm
---> 17 from transformers import AutoTokenizer, BertModel
18
19 from utils_nlp.common.pytorch_utils import (
ModuleNotFoundError: No module named 'transformers'
奇怪的是,utils_nlp.models.transformers.abstractive_summarization_bertsum 中的代码并没有将依赖关系解析为transformers
【问题讨论】:
标签: python github package dependencies google-colaboratory