我嘗試從 github 匯入 Python 包。我在谷歌 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
uj5u.com熱心網友回復:
這是安裝它的正確方法:
pip install git https://github.com/microsoft/nlp-recipes.git
你不能安裝一個模塊,只能安裝一個包。安裝后,您可以繼續使用其余代碼
from utils_nlp import *
...
正如您可以在安裝指南中閱讀的那樣(安裝軟體包時一定要閱讀):
pip 安裝不會安裝任何必要的包依賴項,預計 conda 將如上所示用于設定正在使用的實用程式的環境。
這解釋了您的錯誤:該transformers軟體包未自動安裝,您需要自行安裝(只需使用pip install transformers)。setup.py檔案中也證實了這一點:沒有“install_requires”依賴項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409337.html
標籤:
