Raspberry pi and Python 3.7 : zipimport.ZipImportError: can't decompress data; zlib not available

The error

When you install python 3.7 on raspberry pi from sources and you get the error:

Last 10 log lines:
  File "/tmp/python-build.20191011035453.21409/Python-3.7.2/Lib/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/tmp/python-build.20191011035453.21409/Python-3.7.2/Lib/ensurepip/__init__.py", line 204, in _main
    default_pip=args.default_pip,
  File "/tmp/python-build.20191011035453.21409/Python-3.7.2/Lib/ensurepip/__init__.py", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/tmp/python-build.20191011035453.21409/Python-3.7.2/Lib/ensurepip/__init__.py", line 27, in _run_pip
    import pip._internal
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [Makefile:1130: install] Error 1

Solution

Install zlib with the following command:

sudo apt-get install zlib1g-dev