用PyInstaller把Python代碼打包成單個(gè)獨(dú)立的exe可執(zhí)行文件
之前就想要把自己的BlogsToWordpress打開成exe了。一直沒(méi)去弄。
又看到有人提到python打開成exe的問(wèn)題。
所以打算現(xiàn)在就去試試。
注:此處之所有選用BlogsToWordpress,是因?yàn)榇藀ython腳本夠復(fù)雜,依賴的模塊夠多。
如果這個(gè)都搞定了,那么其他單個(gè)的python文件,和小python項(xiàng)目的打包,就更不成問(wèn)題了。
1.先去找找,目前主流有哪幾種方法。
找到幾個(gè)名字
cx_Freeze
PyInstaller
py2exe
2.關(guān)于py2exe和PyInstaller的兩者官網(wǎng):
http://www.py2exe.org/index.cgi/FAQ
和
比較了一下,發(fā)現(xiàn)貌似后者更好用。
因?yàn)槊菜苝y2exe還需要另外的其他庫(kù)文件啊啥的,太瑣碎。
而PyInstaller:
- 可以只是生成單獨(dú)的可執(zhí)行程序
- 且支持的版本也多:2.3到2.7都支持。以及x64也支持
- 也可以自定義圖標(biāo)
所以先去試試PyInstaller。
3.從主頁(yè)
中下載對(duì)應(yīng)的zip包:
https://github.com/downloads/pyinstaller/pyinstaller/pyinstaller-2.0.zip
得到3M+的pyinstaller-2.0.zip,解壓,打開cmd,進(jìn)入對(duì)應(yīng)目錄,去安裝,結(jié)果說(shuō)不支持:
D:\tmp\dev_tools\python\to_exe\PyInstaller\pyinstaller-2.0>setup.py install
setup.py is not yet supposed to work. Please Use PyInstaller without installation.
所以算了,還是參考官網(wǎng)文檔,一點(diǎn)點(diǎn)折騰吧。
4.參考在線文檔:
http://www.pyinstaller.org/export/v2.0/project/doc/Manual.html?format=raw
結(jié)果說(shuō)需要PyWin32,所以得先去裝這個(gè)。
5.后來(lái)才發(fā)現(xiàn),原來(lái)之前已經(jīng)安裝過(guò)了:
【已解決】Python中出錯(cuò):ImportError: No module named win32com.client
但是要注意的是,import不是pywin32,而是win32com:
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pywin32 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named pywin32 >>> import win32com >>>
6.繼續(xù)參考:
發(fā)現(xiàn),解壓后,就算是安裝好了。
7.在一個(gè)文件夾中,準(zhǔn)備好自己的Python程序:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress
以備后用。
8.去到pyinstaller.py所在目錄,去運(yùn)行:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>pyinstaller.py ..\BlogsToWordpress\BlogsToWordpress.py 232 INFO: wrote D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\BlogsToWordpress.spec 250 INFO: Testing for ability to set icons, version resources... 269 INFO: ... resource update available 272 INFO: UPX is not available. 1437 INFO: checking Analysis 1437 INFO: building Analysis because out00-Analysis.toc non existent 1437 INFO: running Analysis out00-Analysis.toc 1439 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 3074 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 3075 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b.manifest 3081 INFO: Searching for file msvcr90.dll 3081 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll 3081 INFO: Searching for file msvcp90.dll 3082 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcp90.dll 3082 INFO: Searching for file msvcm90.dll 3082 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcm90.dll 3292 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support\_pyi_bootstrap.py 4048 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\archive.py 4101 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\carchive.py 4159 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.py 4176 INFO: Analyzing ..\BlogsToWordpress\BlogsToWordpress.py 4880 INFO: Hidden import 'encodings' has been found otherwise 4881 INFO: Looking for run-time hooks 4881 INFO: Analyzing rthook D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support/rthooks/pyi_rth_encodings.py 5523 INFO: Warnings written to D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\warnBlogsToWordpress.txt 5528 INFO: checking PYZ 5529 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing 5529 INFO: building PYZ out00-PYZ.toc 6225 INFO: checking PKG 6226 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing 6226 INFO: building PKG out00-PKG.pkg 6246 INFO: checking EXE 6246 INFO: rebuilding out00-EXE.toc because BlogsToWordpress.exe missing 6248 INFO: building EXE from out00-EXE.toc 6256 INFO: Appending archive to EXE D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\BlogsToWordpress.exe 6259 INFO: checking COLLECT 6259 INFO: building COLLECT out00-COLLECT.toc D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>
可以看到:
當(dāng)前pyinstaller下面,的確生成了對(duì)應(yīng)的BlogsToWordpress文件夾:
其下,也有對(duì)應(yīng)的:
都已經(jīng)生成了對(duì)應(yīng)的exe了:
dist下面,有對(duì)應(yīng)的,exe,pyd,dll等等:
汗,效率也忒高了,我還以為,需要折騰半天才可以呢,囧。。。。
9.先去試試生成的exe,是否滿足我們的需求,是否可以獨(dú)立運(yùn)行。
不過(guò)運(yùn)行之前,還是去先研究一下對(duì)應(yīng)的參數(shù)吧。
看到了:
What to generate:
-F, --onefile
create a single file deployment
-D, --onedir
create a single directory deployment (default)
-o DIR, --out=DIR
create the spec file in directory. If not specified, and the current directory is Installer's root directory, an output subdirectory will be created. Otherwise the current directory is used.
-n NAME, --name=NAME
optional name to assign to the project (from which the spec file name is generated). If omitted, the basename of the (first) script is used.
很明顯,默認(rèn)用的是-D,所以生成的是帶目錄的,現(xiàn)在重新去執(zhí)行一次,使用-F生成單一的文件。
10.刪掉舊的。重新運(yùn)行:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>pyinstaller.py -F ..\BlogsToWordpress\BlogsToWordpress.py 39 INFO: wrote D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\BlogsToWordpress.spec 55 INFO: Testing for ability to set icons, version resources... 62 INFO: ... resource update available 63 INFO: UPX is not available. 848 INFO: checking Analysis 848 INFO: building Analysis because out00-Analysis.toc non existent 849 INFO: running Analysis out00-Analysis.toc 851 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 905 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 907 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b.manifest 908 INFO: Searching for file msvcr90.dll 908 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll 911 INFO: Searching for file msvcp90.dll 911 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcp90.dll 912 INFO: Searching for file msvcm90.dll 914 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcm90.dll 987 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support\_pyi_bootstrap.py 1639 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\archive.py 1694 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\carchive.py 1750 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.py 1766 INFO: Analyzing ..\BlogsToWordpress\BlogsToWordpress.py 2246 INFO: Hidden import 'encodings' has been found otherwise 2247 INFO: Looking for run-time hooks 2249 INFO: Analyzing rthook D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support/rthooks/pyi_rth_encodings.py 2608 INFO: Warnings written to D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\warnBlogsToWordpress.txt 2611 INFO: checking PYZ 2612 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing 2613 INFO: building PYZ out00-PYZ.toc 3290 INFO: checking PKG 3290 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing 3292 INFO: building PKG out00-PKG.pkg 4784 INFO: checking EXE 4784 INFO: rebuilding out00-EXE.toc because BlogsToWordpress.exe missing 4786 INFO: building EXE from out00-EXE.toc 4793 INFO: Appending archive to EXE D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist\BlogsToWordpress.exe
去看看結(jié)果。
pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress
下面包含很多toc,pkg,pyz等文件:
dist下面,就生成了,所需要的單個(gè)exe文件:
但是,注意到了,生成文件中,包含一個(gè)警告的文件:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\warnBlogsToWordpress.txt
W: no module named org (delayed import by xml.sax) W: no module named _scproxy (conditional import by urllib) W: no module named cl (delayed, conditional import by aifc) W: no module named pwd (delayed, conditional import by posixpath) W: no module named org (top-level import by pickle) W: no module named Carbon (delayed import by plistlib) W: no module named posix (delayed, conditional import by __main__) W: no module named fcntl (conditional import by subprocess) W: no module named BlogBaidu (top-level import by __main__) W: no module named BlogCsdn (top-level import by __main__) W: no module named BlogBlogbus (top-level import by __main__) W: no module named java (conditional import by xml.sax._exceptions) W: no module named BlogTianya (top-level import by __main__) W: no module named readline (delayed import by pdb) W: no module named AES (delayed, conditional import by archive) W: no module named _emx_link (conditional import by os) W: no module named pwd (delayed import by getpass) W: no module named posix (delayed, conditional import by iu) W: no module named EasyDialogs (conditional import by getpass) W: no module named termios (top-level import by getpass) W: no module named gestalt (delayed import by platform) W: no module named org (top-level import by copy) W: no module named fcntl (top-level import by tempfile) W: no module named readline (delayed, conditional import by cmd) W: no module named crifanLib (top-level import by __main__) W: no module named SOCKS (top-level import by ftplib) W: no module named java (delayed import by platform) W: no module named cl (delayed import by aifc) W: no module named BlogQQ (top-level import by __main__) W: no module named xmlparse (top-level import by pyexpat) W: no module named xmltok (top-level import by pyexpat) W: no module named BlogDiandian (top-level import by __main__) W: no module named BlogSohu (top-level import by __main__) W: no module named BlogRenren (top-level import by __main__) W: no module named AES (delayed, conditional import by __main__) W: no module named posix (conditional import by os) W: no module named BlogNetease (top-level import by __main__) W: no module named MacOS (delayed import by platform) W: no module named vms_lib (delayed, conditional import by platform) W: no module named rourl2path (conditional import by urllib) W: no module named _xmlplus (top-level import by xml) W: no module named Crypt (delayed, conditional import by __main__) W: no module named BlogSina (top-level import by __main__) W: delayed exec statement detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed __import__ hack detected at line 0 - optparse (D:\tmp\dev_install_root\Python27_x64\lib\optparse.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: delayed exec statement detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: __all__ is built strangely at line 0 - tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc) W: __all__ is built strangely at line 0 - tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc) W: delayed __import__ hack detected at line 0 - pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - encodings (D:\tmp\dev_install_root\Python27_x64\lib\encodings\__init__.pyc) W: __all__ is built strangely at line 0 - dis (D:\tmp\dev_install_root\Python27_x64\lib\dis.pyc) W: __all__ is built strangely at line 0 - hashlib (D:\tmp\dev_install_root\Python27_x64\lib\hashlib.pyc) W: delayed conditional eval hack detected at line 0 - warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc) W: delayed conditional __import__ hack detected at line 0 - warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc) W: delayed __import__ hack detected at line 0 - email (D:\tmp\dev_install_root\Python27_x64\lib\email\__init__.pyc) W: delayed exec statement detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional exec statement detected at line 0 - iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc) W: delayed conditional exec statement detected at line 0 - iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc) W: __all__ is built strangely at line 0 - collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc) W: delayed exec statement detected at line 0 - collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.main (D:\tmp\dev_install_root\Python27_x64\lib\unittest\main.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: delayed __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: __all__ is built strangely at line 0 - __future__ (D:\tmp\dev_install_root\Python27_x64\lib\__future__.pyc) W: delayed __import__ hack detected at line 0 - xml.sax (D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\__init__.pyc) W: delayed eval hack detected at line 0 - gettext (D:\tmp\dev_install_root\Python27_x64\lib\gettext.pyc)
不知道是否影響程序。
11.去運(yùn)行單個(gè)的exe,看看效果。
結(jié)果直接出錯(cuò):
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist>BlogsToWordpress.exe Traceback (most recent call last): File "<string>", line 127, in <module> File "D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.py", line 409, in importHook raise ImportError("No module named %s" % fqname) ImportError: No module named crifanLib
很明顯,還是無(wú)法自動(dòng)導(dǎo)入很多的庫(kù)啊。
去想辦法,添加搜索路徑,讓其找到對(duì)應(yīng)的庫(kù)。
12.好像是-p參數(shù):
-p DIR, --paths=DIR
set base path for import (like using PYTHONPATH). Multiple directories are allowed, separating them with the path separator (‘;' under Windows, ‘:' under Linux), or using this option multiple times.
去試試:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>pyinstaller.py -F -p D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs;D:\tmp\tmp_dev_root\python\tutorial _summary\make_exe\BlogsToWordpress\libs\crifan;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsT oWordpress\libs\thirdparty;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet; ..\BlogsToWordpress\BlogsToWordpress.py 18 INFO: wrote D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\BlogsToWordpress.spec 33 INFO: Testing for ability to set icons, version resources... 36 INFO: ... resource update available 39 INFO: UPX is not available. 674 INFO: checking Analysis 677 INFO: building because pathex changed 679 INFO: running Analysis out00-Analysis.toc 680 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 733 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 735 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b.manifest 736 INFO: Searching for file msvcr90.dll 736 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll 738 INFO: Searching for file msvcp90.dll 739 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcp90.dll 740 INFO: Searching for file msvcm90.dll 743 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcm90.dll 812 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support\_pyi_bootstrap.py 1512 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\archive.py 1578 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\carchive.py 1648 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.py 1667 INFO: Analyzing ..\BlogsToWordpress\BlogsToWordpress.py 3016 INFO: Hidden import 'encodings' has been found otherwise 3016 INFO: Looking for run-time hooks 3018 INFO: Analyzing rthook D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support/rthooks/pyi_rth_encodings.py 3670 INFO: Warnings written to D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\warnBlogsToWordpress.txt 3674 INFO: checking PYZ 3679 INFO: building because toc changed 3679 INFO: building PYZ out00-PYZ.toc 5713 INFO: checking PKG 5716 INFO: building because D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\out00-PYZ.pyz changed 5717 INFO: building PKG out00-PKG.pkg 7163 INFO: checking EXE 7164 INFO: rebuilding out00-EXE.toc because pkg is more recent 7164 INFO: building EXE from out00-EXE.toc 7167 INFO: Appending archive to EXE D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist\BlogsToWordpress.exe D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>
添加上路徑后,生成的exe,的確也大了一點(diǎn),變成4505KB了:
另外,warnBlogsToWordpress.txt中,的確沒(méi)了crifanLib,但是還是有一些其他,可能要依賴的庫(kù):
W: no module named org (delayed import by xml.sax) W: no module named PIL (delayed import by BlogRenren) W: no module named _dummy_threading (top-level import by dummy_threading) W: no module named cl (delayed, conditional import by aifc) W: no module named pwd (delayed, conditional import by posixpath) W: no module named org (top-level import by pickle) W: no module named Carbon (delayed import by plistlib) W: no module named PIL (delayed, conditional import by BlogNetease) W: no module named posix (delayed, conditional import by __main__) W: no module named iconv_codec (top-level import by BeautifulSoup) W: no module named fcntl (conditional import by subprocess) W: no module named MacOS (delayed import by platform) W: no module named readline (delayed import by pdb) W: no module named AES (delayed, conditional import by archive) W: no module named _scproxy (conditional import by urllib) W: no module named pwd (delayed import by getpass) W: no module named posix (delayed, conditional import by iu) W: no module named EasyDialogs (conditional import by getpass) W: no module named termios (top-level import by getpass) W: no module named gestalt (delayed import by platform) W: no module named org (top-level import by copy) W: no module named fcntl (top-level import by tempfile) W: no module named cjkcodecs (top-level import by BeautifulSoup) W: no module named readline (delayed, conditional import by cmd) W: no module named java (delayed import by platform) W: no module named cl (delayed import by aifc) W: no module named xmlparse (top-level import by pyexpat) W: no module named xmltok (top-level import by pyexpat) W: no module named java (conditional import by xml.sax._exceptions) W: no module named _emx_link (conditional import by os) W: no module named posix (conditional import by os) W: no module named rourl2path (conditional import by urllib) W: no module named vms_lib (delayed, conditional import by platform) W: no module named SOCKS (top-level import by ftplib) W: no module named _xmlplus (top-level import by xml) W: no module named Crypt (delayed, conditional import by __main__) W: no module named AES (delayed, conditional import by __main__) W: delayed exec statement detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed __import__ hack detected at line 0 - optparse (D:\tmp\dev_install_root\Python27_x64\lib\optparse.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: delayed exec statement detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: __all__ is built strangely at line 0 - tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc) W: __all__ is built strangely at line 0 - tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc) W: delayed __import__ hack detected at line 0 - pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - encodings (D:\tmp\dev_install_root\Python27_x64\lib\encodings\__init__.pyc) W: __all__ is built strangely at line 0 - dummy_threading (D:\tmp\dev_install_root\Python27_x64\lib\dummy_threading.pyc) W: __all__ is built strangely at line 0 - dis (D:\tmp\dev_install_root\Python27_x64\lib\dis.pyc) W: __all__ is built strangely at line 0 - hashlib (D:\tmp\dev_install_root\Python27_x64\lib\hashlib.pyc) W: delayed conditional eval hack detected at line 0 - warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc) W: delayed conditional __import__ hack detected at line 0 - warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc) W: delayed __import__ hack detected at line 0 - email (D:\tmp\dev_install_root\Python27_x64\lib\email\__init__.pyc) W: delayed exec statement detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional exec statement detected at line 0 - iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc) W: delayed conditional exec statement detected at line 0 - iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc) W: __all__ is built strangely at line 0 - collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc) W: delayed exec statement detected at line 0 - collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.main (D:\tmp\dev_install_root\Python27_x64\lib\unittest\main.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: delayed __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: __all__ is built strangely at line 0 - __future__ (D:\tmp\dev_install_root\Python27_x64\lib\__future__.pyc) W: delayed __import__ hack detected at line 0 - xml.sax (D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\__init__.pyc) W: delayed eval hack detected at line 0 - gettext (D:\tmp\dev_install_root\Python27_x64\lib\gettext.pyc)
比如,其中的PIL等庫(kù)。
不過(guò),關(guān)于PIL,我去看了看自己的
D:\tmp\dev_install_root\Python27_x64\Lib\site-packages
中的確沒(méi)有,應(yīng)該是重裝python,導(dǎo)致了之前安裝好的PIL沒(méi)了。
所以,還是需要自己重新安裝一下PIL的。
12.關(guān)于安裝PIL的過(guò)程,詳見:
【記錄】下載和安裝Python的第三方圖像處理的庫(kù):PIL(Python Imaging Library)
13.然后再去
D:\tmp\dev_install_root\Python27_x64\Lib\site-packages
確認(rèn)一下,果然有了PIL了。
然后此處,刪掉舊的,重新執(zhí)行一次:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>pyinstaller.py -F -p D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs;D:\tmp\tmp_dev_root\python\tutorial _summary\make_exe\BlogsToWordpress\libs\crifan;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsT oWordpress\libs\thirdparty;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet; ..\BlogsToWordpress\BlogsToWordpress.py 18 INFO: wrote D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\BlogsToWordpress.spec 33 INFO: Testing for ability to set icons, version resources... 37 INFO: ... resource update available 39 INFO: UPX is not available. 684 INFO: checking Analysis 684 INFO: building Analysis because out00-Analysis.toc non existent 684 INFO: running Analysis out00-Analysis.toc 685 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 740 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 741 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b.manifest 742 INFO: Searching for file msvcr90.dll 743 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll 744 INFO: Searching for file msvcp90.dll 745 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcp90.dll 747 INFO: Searching for file msvcm90.dll 750 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcm90.dll 821 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support\_pyi_bootstrap.py 1531 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\archive.py 1600 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\carchive.py 1672 INFO: Analyzing D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.py 1692 INFO: Analyzing ..\BlogsToWordpress\BlogsToWordpress.py 2903 INFO: Hidden import 'encodings' has been found otherwise 2904 INFO: Looking for run-time hooks 2905 INFO: Analyzing rthook D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support/rthooks/pyi_rth_PIL_Image.py 2917 INFO: Analyzing rthook D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\support/rthooks/pyi_rth_encodings.py 3319 INFO: Warnings written to D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\warnBlogsToWordpress.txt 3325 INFO: checking PYZ 3326 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing 3326 INFO: building PYZ out00-PYZ.toc 5360 INFO: checking PKG 5360 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing 5361 INFO: building PKG out00-PKG.pkg 6839 INFO: checking EXE 6839 INFO: rebuilding out00-EXE.toc because BlogsToWordpress.exe missing 6840 INFO: building EXE from out00-EXE.toc 6842 INFO: Appending archive to EXE D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist\BlogsToWordpress.exe D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>
雖然結(jié)果警告中,也還是有PIL:
W: no module named org (delayed import by xml.sax) W: no module named _dummy_threading (top-level import by dummy_threading) W: no module named cl (delayed, conditional import by aifc) W: no module named pwd (delayed, conditional import by posixpath) W: no module named org (top-level import by pickle) W: no module named Carbon (delayed import by plistlib) W: no module named posix (delayed, conditional import by __main__) W: no module named iconv_codec (top-level import by BeautifulSoup) W: no module named fcntl (conditional import by subprocess) W: no module named MacOS (delayed import by platform) W: no module named readline (delayed import by pdb) W: no module named AES (delayed, conditional import by archive) W: no module named _scproxy (conditional import by urllib) W: no module named pwd (delayed import by getpass) W: no module named posix (delayed, conditional import by iu) W: no module named EasyDialogs (conditional import by getpass) W: no module named termios (top-level import by getpass) W: no module named gestalt (delayed import by platform) W: no module named org (top-level import by copy) W: no module named _imaging_gif (top-level import by PIL.GifImagePlugin) W: no module named fcntl (top-level import by tempfile) W: no module named cjkcodecs (top-level import by BeautifulSoup) W: no module named readline (delayed, conditional import by cmd) W: no module named java (delayed import by platform) W: no module named cl (delayed import by aifc) W: no module named xmlparse (top-level import by pyexpat) W: no module named xmltok (top-level import by pyexpat) W: no module named java (conditional import by xml.sax._exceptions) W: no module named _emx_link (conditional import by os) W: no module named posix (conditional import by os) W: no module named ICCProfile (delayed, conditional import by PIL.PngImagePlugin) W: no module named rourl2path (conditional import by urllib) W: no module named vms_lib (delayed, conditional import by platform) W: no module named SOCKS (top-level import by ftplib) W: no module named _xmlplus (top-level import by xml) W: no module named Crypt (delayed, conditional import by __main__) W: no module named AES (delayed, conditional import by __main__) W: delayed exec statement detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (D:\tmp\dev_install_root\Python27_x64\lib\bdb.pyc) W: delayed __import__ hack detected at line 0 - optparse (D:\tmp\dev_install_root\Python27_x64\lib\optparse.pyc) W: delayed __import__ hack detected at line 0 - PIL.Image (D:\tmp\dev_install_root\Python27_x64\lib\site-packages\PIL\Image.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: delayed exec statement detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (D:\tmp\dev_install_root\Python27_x64\lib\doctest.pyc) W: __all__ is built strangely at line 0 - tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc) W: __all__ is built strangely at line 0 - tokenize (D:\tmp\dev_install_root\Python27_x64\lib\tokenize.pyc) W: delayed __import__ hack detected at line 0 - pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - pickle (D:\tmp\dev_install_root\Python27_x64\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - encodings (D:\tmp\dev_install_root\Python27_x64\lib\encodings\__init__.pyc) W: __all__ is built strangely at line 0 - dummy_threading (D:\tmp\dev_install_root\Python27_x64\lib\dummy_threading.pyc) W: __all__ is built strangely at line 0 - dis (D:\tmp\dev_install_root\Python27_x64\lib\dis.pyc) W: __all__ is built strangely at line 0 - hashlib (D:\tmp\dev_install_root\Python27_x64\lib\hashlib.pyc) W: delayed conditional eval hack detected at line 0 - warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc) W: delayed conditional __import__ hack detected at line 0 - warnings (D:\tmp\dev_install_root\Python27_x64\lib\warnings.pyc) W: delayed __import__ hack detected at line 0 - email (D:\tmp\dev_install_root\Python27_x64\lib\email\__init__.pyc) W: delayed exec statement detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (D:\tmp\dev_install_root\Python27_x64\lib\pdb.pyc) W: delayed conditional exec statement detected at line 0 - iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc) W: delayed conditional exec statement detected at line 0 - iu (D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\PyInstaller\loader\iu.pyc) W: __all__ is built strangely at line 0 - collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc) W: delayed exec statement detected at line 0 - collections (D:\tmp\dev_install_root\Python27_x64\lib\collections.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.main (D:\tmp\dev_install_root\Python27_x64\lib\unittest\main.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: delayed __import__ hack detected at line 0 - unittest.loader (D:\tmp\dev_install_root\Python27_x64\lib\unittest\loader.pyc) W: __all__ is built strangely at line 0 - __future__ (D:\tmp\dev_install_root\Python27_x64\lib\__future__.pyc) W: delayed __import__ hack detected at line 0 - xml.sax (D:\tmp\dev_install_root\Python27_x64\lib\xml\sax\__init__.pyc) W: delayed eval hack detected at line 0 - gettext (D:\tmp\dev_install_root\Python27_x64\lib\gettext.pyc)
但是很明顯,只是PIL模塊內(nèi)部的一些小問(wèn)題罷了,不理會(huì)。
生成的exe,的確又變大了,4748KB:
13.去運(yùn)行現(xiàn)在的最新的BlogsToWordpress.exe,看看效果如何。
果然是可以,如期望的一樣,去執(zhí)行了:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist>BlogsToWordpress.exe Imported: crifanLib, v2.4 Imported: BlogNetease, v1.4 Imported: BlogBaidu, v3.4 Imported: BlogSina, v1.5 Imported: BlogQQ, v1.8 Imported: BlogCsdn, v1.1 Imported: BlogSohu, v1.3 LINE 1600 : INFO Current runtime info: LINE 1600 : INFO Paramenters : ['D:\\tmp\\tmp_dev_root\\python\\tutorial_summary\\make_exe\\pyinstaller-2.0\\BlogsToWordpress\\dist\\BlogsToWordpress.exe'] LINE 1600 : INFO Python version : sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0) LINE 1600 : INFO platform.machine()=AMD64 LINE 1600 : INFO platform.node()=PC-CLI-1 LINE 1600 : INFO platform.platform()=Windows-7-6.1.7601-SP1 LINE 1600 : INFO platform.processor()=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel LINE 1600 : INFO platform.python_build()=('default', 'Apr 10 2012 23:24:47') LINE 1600 : INFO platform.python_compiler()=MSC v.1500 64 bit (AMD64) LINE 1600 : INFO platform.python_branch()= LINE 1600 : INFO platform.python_implementation()=CPython LINE 1600 : INFO platform.python_revision()= LINE 1600 : INFO platform.python_version()=2.7.3 LINE 1600 : INFO platform.python_version_tuple()=('2', '7', '3') LINE 1600 : INFO platform.release()=7 LINE 1600 : INFO platform.system()=Windows LINE 1600 : INFO platform.version()=6.1.7601 LINE 1600 : INFO platform.uname()=('Windows', 'PC-CLI-1', '7', '6.1.7601', 'AMD64', 'Intel64 Family 6 Model 42 Stepping 7, GenuineIntel') LINE 1600 : INFO Default encoding : ascii LINE 1600 : INFO Current path : C:\Users\CLi\AppData\Local\Temp\_MEI252922 LINE 1600 : INFO 版本信息:v16.8 LINE 1600 : INFO 1.如果腳本運(yùn)行出錯(cuò),請(qǐng)務(wù)必把上述(1)從腳本開始運(yùn)行到上述所打印出來(lái)的系統(tǒng)信息(2)出錯(cuò)時(shí)候的相關(guān)信息(3)腳本所生成的BlogsToWordpress.log文件,通過(guò)復(fù)制粘貼、截圖、附件等方式 LINE 1600 : INFO 發(fā)送至admin(at)crifan.com或跟帖(下面有地址)回復(fù),否則如果沒(méi)有足夠的錯(cuò)誤相關(guān)信息,我就是想幫你解決問(wèn)題,也沒(méi)法幫啊! LINE 1600 : INFO 2.如對(duì)此腳本使用有任何疑問(wèn),請(qǐng)輸入-h參數(shù)以獲得相應(yīng)的參數(shù)說(shuō)明。 LINE 1600 : INFO 3.關(guān)于本程序詳細(xì)的使用說(shuō)明和更多相關(guān)信息,請(qǐng)參考: LINE 1600 : INFO BlogsToWordPress:將百度空間(新版和舊版),網(wǎng)易163,新浪Sina,QQ空間,人人網(wǎng),CSDN,搜狐Sohu,博客大巴Blogbus,天涯博客,點(diǎn)點(diǎn)輕博客等博客搬家到WordPress LINE 1600 : INFO https://www.crifan.com/crifan_released_all/website/python/blogstowordpress/ LINE 1600 : INFO -------------------------------------------------------------------------------- LINE 1600 : INFO Your process type of post is: Export post to WXR(WordPress eXtended Rss). LINE 1575 : ERROR Must designate the entry URL for the first blog item ! LINE 1575 : ERROR Unknown Error ! Traceback (most recent call last): File "<string>", line 1931, in <module> File "<string>", line 1655, in main SystemExit: 2 D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist>
加上對(duì)應(yīng)參數(shù),再試試:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist>BlogsToWordpress.exe -s http://againinput4.blog.163.com Imported: crifanLib, v2.4 Imported: BlogNetease, v1.4 Imported: BlogBaidu, v3.4 Imported: BlogSina, v1.5 Imported: BlogQQ, v1.8 Imported: BlogCsdn, v1.1 Imported: BlogSohu, v1.3 LINE 1600 : INFO Current runtime info: LINE 1600 : INFO Paramenters : ['D:\\tmp\\tmp_dev_root\\python\\tutorial_summary\\make_exe\\pyinstaller-2.0\\BlogsToWordpress\\dist\\BlogsToWordpress.exe', '-s', 'http://againinput4.blog.163 .com'] LINE 1600 : INFO Python version : sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0) LINE 1600 : INFO platform.machine()=AMD64 LINE 1600 : INFO platform.node()=PC-CLI-1 LINE 1600 : INFO platform.platform()=Windows-7-6.1.7601-SP1 LINE 1600 : INFO platform.processor()=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel LINE 1600 : INFO platform.python_build()=('default', 'Apr 10 2012 23:24:47') LINE 1600 : INFO platform.python_compiler()=MSC v.1500 64 bit (AMD64) ...
的確就是可以正常執(zhí)行了。
剩下的,就是要拿到別的windows平臺(tái)上,多測(cè)試測(cè)試,是否都正常。
14.接著打算再去試試,添加icon圖標(biāo)的事情。
參考官網(wǎng)的參數(shù)解釋:
-r FILE[,TYPE[,NAME[,LANGUAGE]]], –resource=FILE[,TYPE[,NAME[,LANGUAGE]]]
add/update resource of the given type, name and language from FILE to the final executable. FILE can be a data file or an exe/dll. For data files, atleast TYPE and NAME need to be specified, LANGUAGE defaults to 0 or may be specified as wildcard * to update all resources of the given TYPE and NAME. For exe/dll files, all resources from FILE will be added/updated to the final executable if TYPE, NAME and LANGUAGE are omitted or specified as wildcard *.Multiple resources are allowed, using this option multiple times.
去運(yùn)行:
D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0>pyinstaller.py -F -p D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs;D:\tmp\tmp_dev_root\python\tutorial _summary\make_exe\BlogsToWordpress\libs\crifan;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsT oWordpress\libs\thirdparty;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet; -i ..\BlogsToWordpress\BlogsToWordpress.ico ..\BlogsToWordpress\BlogsToWordpre ss.py 18 INFO: wrote D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\BlogsToWordpress.spec 34 INFO: Testing for ability to set icons, version resources... 37 INFO: ... resource update available 40 INFO: UPX is not available. 681 INFO: checking Analysis 696 INFO: checking PYZ 709 INFO: checking PKG 711 INFO: building because D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress\BlogsToWordpress.exe.manifest changed 712 INFO: building PKG out00-PKG.pkg 2190 INFO: checking EXE 2192 INFO: building because icon changed 2192 INFO: building EXE from out00-EXE.toc 2207 INFO: SRCPATH [('..\\BlogsToWordpress\\BlogsToWordpress.ico', None)] 2207 INFO: Updating icons from ['..\\BlogsToWordpress\\BlogsToWordpress.ico'] to c:\users\cli\appdata\local\temp\tmpouutgx 2209 INFO: Writing RT_GROUP_ICON 0 resource with 34 bytes 2211 INFO: Writing RT_ICON 1 resource with 1128 bytes 2213 INFO: Writing RT_ICON 2 resource with 4264 bytes 2222 INFO: Appending archive to EXE D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\pyinstaller-2.0\BlogsToWordpress\dist\BlogsToWordpress.exe
可以看到,其自動(dòng)會(huì)把icon添加到當(dāng)前已有的exe中,然后可以看到對(duì)應(yīng)的,帶圖標(biāo)的exe的效果:
總結(jié)
PyInstaller,的確非常好用啊。感謝作者們。
簡(jiǎn)單總結(jié)其使用方法:
生成單一的exe文件:
pyinstaller.py -F ..\BlogsToWordpress\BlogsToWordpress.py
添加必要的搜索路徑:
pyinstaller.py -F -p D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet; ..\BlogsToWordpress\BlogsToWordpress.py
添加必要的搜索路徑,且?guī)D標(biāo):
pyinstaller.py -F -p D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\crifan\blogModules;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty;D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress\libs\thirdparty\chardet; -i ..\BlogsToWordpress\BlogsToWordpress.ico ..\BlogsToWordpress\BlogsToWordpress.py
需要注意的是:
1.檢查生成的
pyinstaller-2.0\XXX\build\pyi.win32\XXX\warnXXX.txt
(XXX是你的項(xiàng)目名)
中,是否缺少了必要的模塊。
如果有缺少的,那么去如上所述,添加必要的搜素路徑,使得pyinstaller在運(yùn)行時(shí),可以找到對(duì)應(yīng)的模塊并集成進(jìn)來(lái)。
2.此處我這里沒(méi)有UPX,暫時(shí)沒(méi)去折騰。
估計(jì)是用UPX去壓縮,壓縮后所生成的exe文件的大小,會(huì)小得多。
- Python打包方法Pyinstaller的使用
- python-pyinstaller、打包后獲取路徑的實(shí)例
- Python中用pyinstaller打包時(shí)的圖標(biāo)問(wèn)題及解決方法
- python3.9實(shí)現(xiàn)pyinstaller打包python文件成exe
- 教你使用pyinstaller打包Python教程
- python使用Pyinstaller如何打包整個(gè)項(xiàng)目
- PyInstaller?完美打包?Python?腳本
- Python?pyinstaller打包exe最新完整圖文教程
- Python使用pyinstaller打包成.exe文件執(zhí)行后閃退的圖文解決辦法
- PyInstaller打包Python腳本的使用示例
相關(guān)文章
python golang中g(shù)rpc 使用示例代碼詳解
這篇文章主要介紹了python golang中g(shù)rpc 使用,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06python使用openpyxl打開及讀取excel表格過(guò)程
openpyxl是一個(gè)Python庫(kù),用于讀寫Excel?2010?xlsx/xlsm文件,它允許你輕松工作與Excel表格,進(jìn)行數(shù)據(jù)處理和分析,支持讀取、創(chuàng)建和修改Excel文件,甚至可以在Excel中插入圖表等,安裝非常簡(jiǎn)單,只需要使用pip命令即可2024-09-09pyecharts調(diào)整圖例與各板塊的位置間距實(shí)例
這篇文章主要介紹了pyecharts調(diào)整圖例與各板塊的位置間距實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05Python使用future處理并發(fā)問(wèn)題方案詳解
從Python3.2引入的concurrent.futures模塊,Python2.5以上需要在pypi中安裝futures包。future指一種對(duì)象,表示異步執(zhí)行的操作。這個(gè)概念的作用很大,是concurrent.futures模塊和asyncio包的基礎(chǔ)2023-02-02淺談Python xlwings 讀取Excel文件的正確姿勢(shì)
這篇文章主要介紹了淺談Python xlwings 讀取Excel文件的正確姿勢(shì),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02Python數(shù)據(jù)類型轉(zhuǎn)換實(shí)現(xiàn)方法
這篇文章主要介紹了Python數(shù)據(jù)類型轉(zhuǎn)換的實(shí)現(xiàn),有時(shí)候,我們需要對(duì)數(shù)據(jù)內(nèi)置的類型進(jìn)行轉(zhuǎn)換,數(shù)據(jù)類型的轉(zhuǎn)換,一般情況下你只需要將數(shù)據(jù)類型作為函數(shù)名即可2022-12-12