code: def bz2_pack(source):
      
      import bz2, base64
      out = ""
      # Preserve shebangs (don't care about encodings for this)
      first_line = source.split('\n')[0]
      if analyze.shebang.match(first_line):
          if py3:
              if first_line.rstrip().endswith('python'): # Make it python3
                  first_line = first_line.rstrip()
                  first_line += '3' #!/usr/bin/env python3
          out = first_line + '\n'
      compressed_source = bz2.compress(source.encode('utf-8'))
      out += 'import bz2, base64\n'
      out += "exec(bz2.decompress(base64.b64decode('"
      out += base64.b64encode(compressed_source).decode('utf-8')
      out += "')))\n"
      return out
docs: Returns 'source' as a bzip2-compressed, self-extracting python script.
  
      .. note::
  
          This method uses up more space than the zip_pack method but it has the
          advantage in that the resulting .py file can still be imported into a
          python program.