我想將我的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建議,但沒有任何幫助,我總是得到這個錯誤。有任何想法嗎?
單文件可執行文件不是linux的方式。用依賴關係創建一個deb包。 –
感謝您的評論,但我並未製作單一文件版本。我知道這不是最完美的方式,但我需要製作一個多平臺,易於安裝的獨立版本。任何想法爲什麼PyInstaller不接受numpy?我甚至試圖重新安裝python和numpy,但仍然是同樣的問題。 – Anton