嘗試手動安裝從源代碼(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