尝试手动安装从源代码(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'
我已经通过以下步骤解决了问题。
访问http://www.zlib.net/并下载zlib-1.2.11。
安装zlib(解压缩,配置,make,make install)。
重新安装Python3.6.1(make clean,make)。
我发现制作过程没有抱怨zlib失踪了,我可以在shell中成功导入zlib。其实,为了解决这类问题,我们可能会从源代码中找到一些提示。 我们可以在“setup.py”找到下面的代码,这些注释非常有帮助。我们可以通过调试信息修改代码来确定问题的真正位置(对我而言,这是因为第一次如果由于缺少zlib.h而导致检查失败)。
# 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')
运行3个命令和重定向每个的_stdout_(和_stderr_)到一个文件中(例如:'的./configure> configure_out.txt 2>&1'),然后让这些3个文件的地方访问。这两个_Python_模块都依赖_zlib_:你可以尝试(如_root_):'apt install zlib1g zlib1g-dev'(至少这些是_Ubtu16(x64)_上的pkg名称),然后再次尝试构建_Python_。 – CristiFati