我試圖通過PyInstaller建立一個python腳本。我用下面的命令來配置,生成一個規範的文件,並建立:PyInstaller,規範文件,導入錯誤:沒有模塊名爲「嗒嗒」
wget pyinstaller.zip, extracted it, python Configure.py, etc, then:
python pyinstaller/Makespec.py --onefile myscript.py
python pyinstaller/Build.py myscript.spec
這裏是它產生的spec文件:
# -*- mode: python -*-
a = Analysis([os.path.join(HOMEPATH,'support/_mountzlib.py'), os.path.join(HOMEPATH,'support/useUnicode.py'), 'icinga.py'],
pathex=['/home/user/projects/icinga_python/releases/v2.1'])
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=os.path.join('dist', 'myscript'),
debug=False,
strip=False,
upx=True,
console=1)
這dist/
目錄生成一個可執行文件。當試圖運行這個文件,我得到如下:
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "/home/user/projects/myscript/releases/v2.1/pyinstaller/iu.py", line 455, in importHook
raise ImportError, "No module named %s" % fqname
ImportError: No module named mysql
如果我搬到這個可執行文件到實際的Python代碼的目錄,它給了不同的結果:
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "/home/user/projects/myscript/releases/v2.1/pyinstaller/iu.py", line 436, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "/home/user/projects/myscript/releases/v2.1/pyinstaller/iu.py", line 521, in doimport
exec co in mod.__dict__
File "CLUSTER/mysql/icingasql.py", line 13, in <module>
import urllib2
File "/home/user/projects/myscript/releases/v2.1/pyinstaller/iu.py", line 455, in importHook
raise ImportError, "No module named %s" % fqname
ImportError: No module named urllib2
在... pyinstaller docs我看到--onefile
是我需要/想要的選項,但由於某種原因不能代表一切正在被編譯。
劇本是不是真的包括任何幻想,只是有點快的模塊,我寫SQL語句,並解析某些網站秒。
我應該嘗試將所有庫放在路徑上,或最終放在PYTHONPATH上,並停止移動庫。 – Louis
對不起,做什麼?是在spec文件中? – Cmag
http://docs.python.org/tutorial/modules.html – Louis