变压器负载问题; ModuleNotFoundError:没有名为“transformers”的模块

问题描述 投票:0回答:1

我想使用huggingface 提供的一些模型。我什至在开始时都遇到了最困难的时刻。谁能帮我识别并解决这个问题?

我使用的是 Kubuntu 24.04。


首先,我创建并激活一个虚拟环境来安装变压器。

python3 -m venv .env
source .env/bin/activate

这是成功的,因为现在我在 Visual Code Studio 中的终端具有前缀“

(.env)
”。

接下来,我从 github 安装最新的 Transformer:

pip install git+https://github.com/huggingface/transformers

输出成功。然后我用 Hugginface.co 上推荐的方法测试其成功:

python3 -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('I love you'))"

输出对我来说看起来很正确:

No model was supplied, defaulted to distilbert/distilbert-base-uncased-finetuned-sst-2-english and revision 714eb0f (https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.
Hardware accelerator e.g. GPU is available in the environment, but no `device` argument is passed to the `Pipeline` object. Model will be on CPU.
[{'label': 'POSITIVE', 'score': 0.9998656511306763}]

从那里,我尝试运行以下代码:

from transformers import pipeline

但每次我得到以下输出:

/bin/python3 /path-to/main.py
Traceback (most recent call last):
  File "/path-to/main.py", line 5, in <module>
    from transformers import pipeline
ModuleNotFoundError: No module named 'transformers'
python machine-learning huggingface-transformers
1个回答
0
投票

我建议您在激活虚拟环境的终端中运行代码

© www.soinside.com 2019 - 2024. All rights reserved.