The answers on this site mostly suggest using bzip2 and bunzip, but I can't install them in Google Collab.

1 Answer 1


You can run external commands (shell commands) by prepending them with a !, and bzip2 and bunzip2 are standard Linux commands and should be pre-installed and available to you.

[ ] !bunzip2 path/to/myfile.bz2


[ ] !bzip2 -d path/to/myfile.bz2

If that doesn't work, you can then use Python code to access the file, in which case the bz2 module will be helpful.

[ ] import bz2, shutil
    with bz2.BZ2File('path/to/compressed.bz2') as in:
        with open('path/to/uncompressed', 'w') as out:
            shutil.copyfileobj(in, out)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.