Zlib 和 binascii 不使用 Python3.6 构建

Zlib and binascii don't build with Python3.6

我一直在尝试从 Ubuntu 14.04 上的源代码构建 Python3.6.1。 README 推荐的命令顺序:

./configure
make
make test

后者因为无法导入binascii而崩溃。在其输出中有以下内容:

Following modules built successfully but were removed because they could not be imported:
binascii              zlib 

尝试跳过 make test 并开始 make install 我在导入失败 zlib 后崩溃了。 Ubuntu 论坛中的一些人建议从存储库更新所有 zlib 的包。那没有帮助。我该如何解决这个问题?

尝试从源代码 (http://www.zlib.net/) 手动安装 zlib (而不是通过 yum/apt-get/brew...) 可能会有帮助。

我已经在我的 mac 开发中尝试了 Python3.6.1 构建,也遇到了您的问题。它在制作后抱怨以下消息。

Python build finished successfully!
The necessary bits to build these optional modules were not found:
       ... zlib ...

而且我也无法在交互式 shell 中导入 zlib。

>>> import zlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'zlib'

我已经通过以下步骤解决了这个问题。

  1. 访问 http://www.zlib.net/ 并下载 zlib-1.2.11.

  2. 安装 zlib(解压、配置、制作、制作安装)。

  3. 重新安装 Python3.6.1(清理,制作)。

我发现制作过程中没有再抱怨缺少zlib,我可以在shell中成功导入zlib。

其实,要解决这类问题,我们可能会从源代码中找到一些提示。 我们可以在 "setup.py" 中找到以下代码,注释非常有帮助。我们可以修改带有调试信息的代码来定位真正的问题所在(对我来说,是因为缺少zlib.h导致第一个if检查失败)。

    # You can upgrade zlib to version 1.1.4 yourself by going to
    # http://www.gzip.org/zlib/
    zlib_inc = find_file('zlib.h', [], inc_dirs)
    have_zlib = False
    if zlib_inc is not None:
        zlib_h = zlib_inc[0] + '/zlib.h'
        version = '"0.0.0"'
        version_req = '"1.1.3"'
        if host_platform == 'darwin' and is_macosx_sdk_path(zlib_h):
            zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:])
        with open(zlib_h) as fp:
            while 1:
                line = fp.readline()
                if not line:
                    break
                if line.startswith('#define ZLIB_VERSION'):
                    version = line.split()[2]
                    break
        if version >= version_req:
            if (self.compiler.find_library_file(lib_dirs, 'z')):
                if host_platform == "darwin":
                    zlib_extra_link_args = ('-Wl,-search_paths_first',)
                else:
                    zlib_extra_link_args = ()
                exts.append( Extension('zlib', ['zlibmodule.c'],
                                       libraries = ['z'],
                                       extra_link_args = zlib_extra_link_args))
                have_zlib = True
            else:
                missing.append('zlib')
        else:
            missing.append('zlib')
    else:
        missing.append('zlib')