2017-07-05 77 views
2

我一直在嘗試從Ubuntu 14.04上的源代碼構建Python3.6.1。命令的順序如README所推薦:Zlib和binascii不能用Python3.6構建

./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的軟件包。這沒有幫助。我該如何解決?

+1

運行3個命令和重定向每個的_stdout_(和_stderr_)到一個文件中(例如:'的./configure> configure_out.txt 2>&1'),然後讓這些3個文件的地方訪問。這兩個_Python_模塊都依賴_zlib_:你可以嘗試(如_root_):'apt install zlib1g zlib1g-dev'(至少這些是_Ubtu16(x64)_上的pkg名稱),然後再次嘗試構建_Python_。 – CristiFati

回答

1

嘗試手動安裝從源代碼(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(解壓縮,配置,make,make install)。

  3. 重新安裝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') 
+0

我遇到了你正在描述的問題,解決了它('sudo apt-get install zlib-dev',如果我的內存正在服務;我現在不在該計算機上),然後*問題就出現了。雖然你是對的,但是檢查setup.py – Synedraacus

+0

似乎很有幫助,它似乎是通過apt-get或yum安裝zlib無法解決您的問題(仍然遇到「ImportError:當導入zlib時沒有名爲'zlib'的模塊」) 。您必須手動從源代碼安裝zlib [http://www.zlib.net/](http://www.zlib.net/)。 – StringToken

+0

好的,我已經接受了答案,但請將澄清:手動安裝添加到答案本身。 – Synedraacus