我一直在尝试从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的软件包。这没有任何帮助。我该如何解决这个问题?
答案 0 :(得分:1)
尝试手动安装源代码(http://www.zlib.net/)中的zlib (不是通过yum / apt-get / brew ...)可能会有所帮助。
我在mac dev中尝试过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(解压缩,配置,制作,安装)。
重新安装Python3.6.1(make clean,make)。
我发现制作过程不再抱怨zlib丢失了,我可以在shell中成功导入zlib。
实际上,为了解决这类问题,我们可能会从源代码中找到一些提示。 我们可以在&#34; setup.py&#34;中找到以下代码。而评论非常有用。我们可以使用调试信息修改代码以找到问题的真正位置(对我来说,这是因为第一次检查因缺少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')