python - ModuleNotFoundError : No module named 'pegasus'

标签 python tensorflow machine-learning nlp google-colaboratory

我想尝试 PEGASUS 来总结文章。 https://github.com/google-research/pegasus
原始 repo 的 README 建议使用 Google Cloud Compute Engine,但我使用 Colaboratory notebook。我是日本的一名英语老师,我希望我的学生能轻松尝试这个软件。他们可以体验机器学习和英语段落摘要。
我遵循了这个指示。 https://github.com/google-research/pegasus/tree/f76b63c2886748f7f5c6c9fb547456d8c6002562#setup
这是我的 colab 笔记本。
https://colab.research.google.com/drive/1p95tZcjhfuCLYh23X3S_gZqRoWVhpIlE?usp=sharing
这是我在笔记本中的代码。

%tensorflow_version 1.x

!git clone https://github.com/google-research/pegasus

!export PYTHONPATH=/content/pegasus

%pip install -r /content/pegasus/requirements.txt

!mkdir /content/pegasus/ckpt

!gsutil cp -r gs://pegasus_ckpt/ /content/pegasus/ckpt/

!python /content/pegasus/pegasus/bin/train.py --params=aeslc_transformer \
--param_overrides=vocab_filename=ckpt/pegasus_ckpt/c4.unigram.newline.10pct.96000.model \
--train_init_checkpoint=ckpt/pegasus_ckpt/model.ckpt-1500000 \
--model_dir=ckpt/pegasus_ckpt/aeslc
然后,我收到此错误消息。
Traceback (most recent call last):
  File "/content/pegasus/pegasus/bin/train.py", line 17, in <module>
    from pegasus.data import infeed
ModuleNotFoundError: No module named 'pegasus'
此错误消息表示 python 无法导入“pegasus”模块,但我使用 !export PYTHONPATH=/content/pegasus 这个命令创建了 python 路径。
请给我一些建议好吗?

最佳答案

你不能使用这个

!export PYTHONPATH=/content/pegasus
改用这个
import os
os.environ['PYTHONPATH'] += ':/content/pegasus'
这里是 an example notebook可以正常运行。
我不使用 /content/pegasus/pegasus .我用 /content/pegasus直接,通过使用 !npx degit .. 安装它

关于python - ModuleNotFoundError : No module named 'pegasus' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62926022/

相关文章:

python - 在 Python 中使用 BeautifulSoup 库

machine-learning - 机器学习-决策树- split 特征值

java - Apache Ignite ML 和 DL 中的 Xgboost 和 LSTM 支持

python - keras loss 是否必须每批输出一个标量或整个批处理输出一个标量?

python-2.7 - BeamSearch 在 Tensorflow 中花费了很长时间

python - "ValueError: Trying to share variable $var, but specified dtype float32 and found dtype float64_ref"尝试使用 get_variable 时

python - 数据框的面积图

python - Django REST 框架 : update() based on query string parameter

python - 如何将压缩的二进制文件读取为 float 组

tensorflow - Pytorch 中的 dim 和 Tensorflow 中的 axis 有什么区别?