6

I would like to use cx_freeze to change my hello_world.py into exe file.

When I run cxfreeze like this:

cxfreeze hello_world.py

And I run the exe file, it comes the error:

./hello_world 
Fatal Python error: Py_Initialize: Unable to get the locale encoding
Traceback (most recent call last):
  File "/home/karl/anaconda3/lib/python3.6/encodings/__init__.py", line 31, in <module>
zipimport.ZipImportError: can't decompress data; zlib not available
Aborted (core dumped)

Does anyone know how to solve this?

karl_TUM
  • 5,769
  • 10
  • 24
  • 41
  • I had a similar issue, maybe this can help you, but it didnt make it for me... https://github.com/peacegiverman/cx_Freeze-deb-wheels – Matt-Mac-Muffin Feb 06 '18 at 11:40

2 Answers2

11

Run the below code which will install zlib:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Thanks to the answer at https://stackoverflow.com/a/52756409/9162193

yl_low
  • 1,209
  • 2
  • 17
  • 26
  • Works on OSX Mojave! Thanks! – chfw Feb 24 '19 at 21:20
  • I get the following error `installer: Error - the package path specified was invalid: '/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg'.` on Mojave 10.14 – qasimalbaqali Mar 05 '19 at 14:49
2

On MacOS the issue is often that an XCode update has removed zlib. The solution in these cases would be running:

xcode-select --install

On Linux machines you would need to install zlib, see for instance this answer.

YPCrumble
  • 26,610
  • 23
  • 107
  • 172
  • 4
    This no longer seems to ship zlib on OSX Mojave – Brad Solomon Oct 24 '18 at 19:29
  • 3
    this returns an error (I am on macOS Mojave, Version 10.14): xcode-select: error: command line tools are already installed, use "Software Update" to install updates – yl_low Nov 09 '18 at 15:10
  • This worked for me on macOS Mojave - https://stackoverflow.com/questions/23749530/brew-install-zlib-devel-on-mac-os-x-mavericks#answer-52900711 – schalkneethling May 01 '19 at 12:48