ModuleNotFoundError: No module named 'pegasus'

Viewed 765

I would like to try PEGASUS to summarize article. https://github.com/google-research/pegasus

The original repo's README suggests to use Google Cloud Compute Engine, but I use Colaboratory notebook. I'm an English teacher in Japan and I hope my students to try this software easily. They can experience both Machine Learning and English passage summarization.

I followed this instruction. https://github.com/google-research/pegasus/tree/f76b63c2886748f7f5c6c9fb547456d8c6002562#setup

This is my colab notebook. https://colab.research.google.com/drive/1p95tZcjhfuCLYh23X3S_gZqRoWVhpIlE?usp=sharing

This is my code in the notebook.

%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

Then, I get this error message.

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'

This error message says that python can't import 'pegasus' module, but I made python path with !export PYTHONPATH=/content/pegasus this command.

Could you give me any advice, please?

1 Answers

You cannot use this

!export PYTHONPATH=/content/pegasus

Use this instead

import os
os.environ['PYTHONPATH'] += ':/content/pegasus'

Here's an example notebook that can run correctly.

I don't use /content/pegasus/pegasus. I use /content/pegasus directly, by installing it with !npx degit ..

Related