0

I launched a new Google Cloud Workstation and create a single python file with these contents:

import bz2
import binascii

original_data = 'This is the original text.'
print ('Original     :', len(original_data), original_data)

compressed = bz2.compress(original_data)
print ('Compressed   :', len(compressed), binascii.hexlify(compressed))

decompressed = bz2.decompress(compressed)
print ('Decompressed :', len(decompressed), decompressed)

When I tried to run this code I received this error:

Traceback (most recent call last):
  File "/home/user/01/app.py", line 1, in <module>
    import bz2
  File "/usr/local/lib/python3.10/bz2.py", line 17, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'

What am I doing wrong?

DanielAttard
  • 3,467
  • 9
  • 55
  • 104
  • ModuleNotFoundError is the result of your python interpreter failing to locate the module where its expects. Either the name is misspelled, it has not been installed, does not exist or is in wrong location. Vesions of this question have been asked multiple times. Search for ModuleNotFoundError in the questions with python tags – Galo do Leste Jan 09 '23 at 04:59
  • You will need to install the support packages or compile Python yourself on the service - the disk/cloud/container image Google provided (that you are currently using) is missing the dependencies needed to provide the `bz2` functionality; picking a different distribution may have a complete Python installation will help. – metatoaster Jan 09 '23 at 05:05

0 Answers0