2015-09-25 47 views
1

我想將我的Python程序轉換爲Windows和Linux的獨立可執行文件。 PyInstaller似乎是這項任務的一個很好的解決方案。它在Windows下很容易轉換,但是我無法使它與Linux一起工作(在兩臺不同的Ubuntu機器上進行探測)。原來的Python程序可以減少到簡單的兩行代碼:PyInstaller與Linux下的NumPy

from numpy import log 
print '%8.6f' % log(5) 

時叫喜歡哪款是工作的罰款:

[email protected]:~/bin$ python test_numpy.py 
1.609438 

在PyInstaller編譯後,它給我的錯誤:

[email protected]:~/bin/dist/test_numpy$ ./test_numpy 
Traceback (most recent call last): 
    File "<string>", line 3, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module 
    exec(bytecode, module.__dict__) 
    File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy", line 153, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module 
    exec(bytecode, module.__dict__) 
    File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.add_newdocs", line 13, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module 
    exec(bytecode, module.__dict__) 
    File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.lib", line 8, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module 
    exec(bytecode, module.__dict__) 
    File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.lib.type_check", line 11, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module 
    exec(bytecode, module.__dict__) 
    File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.core", line 6, in <module> 
ImportError: cannot import name multiarray 

所以這個問題是相關的numpy庫沒有正確導入。

我已經嘗試添加隱藏掛鉤作爲pyinstaller建議,但沒有任何幫助,我總是得到這個錯誤。有任何想法嗎?

+0

單文件可執行文件不是linux的方式。用依賴關係創建一個deb包。 –

+0

感謝您的評論,但我並未製作單一文件版本。我知道這不是最完美的方式,但我需要製作一個多平臺,易於安裝的獨立版本。任何想法爲什麼PyInstaller不接受numpy?我甚至試圖重新安裝python和numpy,但仍然是同樣的問題。 – Anton

回答

0

我終於能夠解決這個問題。

這是我對hithub發現:

The executable that PyInstaller builds is not fully static, in that it still depends on the system libc. Under Linux, the ABI of GLIBC is backward compatible, but not forward compatible. So if you link against a newer GLIBC, you can't run the resulting executable on an older system. The supplied binary bootloader should work with older GLIBC. However, the libpython.so and other dynamic libraries still depends on the newer GLIBC. The solution is to compile the Python interpreter with its modules (and also probably bootloader) on the oldest system you have around, so that it gets linked with the oldest version of GLIBC.

所以出現了目前的穩定版本PyInstaller可能過時。由於降級所有軟件包並不現實,我將PyInstaller升級到了最新的開發版本(3.0.dev2),並聲稱!現在一切都正常工作,正確處理所有的依賴關係,沒有任何自定義鉤子。

希望可以幫助別人。