用PyInstaller把Python代码打包成单个独立的exe可执行文件

之前就想要把自己的BlogsToWordpress打开成exe了。一直没去弄。

又看到有人提到python打开成exe的问题。

所以打算现在就去试试。

注:此处之所有选用BlogsToWordpress,是因为此python脚本够复杂,依赖的模块够多。

如果这个都搞定了,那么其他单个的python文件,和小python项目的打包,就更不成问题了。

1.先去找找,目前主流有哪几种方法。

找到几个名字

cx_Freeze

PyInstaller

py2exe

2.关于py2exe和PyInstaller的两者官网:

http://www.py2exe.org/index.cgi/FAQ

http://www.pyinstaller.org/

比较了一下,发现貌似后者更好用。

因为貌似py2exe还需要另外的其他库文件啊啥的,太琐碎。

而PyInstaller:

  • 可以只是生成单独的可执行程序
  • 且支持的版本也多:2.3到2.7都支持。以及x64也支持
  • 也可以自定义图标

所以先去试试PyInstaller。

3.从主页

http://www.pyinstaller.org/

中下载对应的zip包:

https://github.com/downloads/pyinstaller/pyinstaller/pyinstaller-2.0.zip

得到3M+的pyinstaller-2.0.zip,解压,打开cmd,进入对应目录,去安装,结果说不支持:

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.

所以算了,还是参考官网文档,一点点折腾吧。

4.参考在线文档:

http://www.pyinstaller.org/export/v2.0/project/doc/Manual.html?format=raw

结果说需要PyWin32,所以得先去装这个。

5.后来才发现,原来之前已经安装过了:

【已解决】Python中出错: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.继续参考:

Installing PyInstaller

发现,解压后,就算是安装好了。

7.在一个文件夹中,准备好自己的Python程序:

D:\tmp\tmp_dev_root\python\tutorial_summary\make_exe\BlogsToWordpress

以备后用。

8.去到pyinstaller.py所在目录,去运行:

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>

可以看到:

当前pyinstaller下面,的确生成了对应的BlogsToWordpress文件夹:

其下,也有对应的:

都已经生成了对应的exe了:

dist下面,有对应的,exe,pyd,dll等等:

汗,效率也忒高了,我还以为,需要折腾半天才可以呢,囧。。。。

9.先去试试生成的exe,是否满足我们的需求,是否可以独立运行。

不过运行之前,还是去先研究一下对应的参数吧。

看到了:

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.

很明显,默认用的是-D,所以生成的是带目录的,现在重新去执行一次,使用-F生成单一的文件。

10.删掉旧的。重新运行:

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

去看看结果。

pyinstaller-2.0\BlogsToWordpress\build\pyi.win32\BlogsToWordpress

下面包含很多toc,pkg,pyz等文件:

dist下面,就生成了,所需要的单个exe文件:

但是,注意到了,生成文件中,包含一个警告的文件:

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.去运行单个的exe,看看效果。

结果直接出错:

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

很明显,还是无法自动导入很多的库啊。

去想办法,添加搜索路径,让其找到对应的库。

12.好像是-p参数:

-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,的确也大了一点,变成4505KB了:

另外,warnBlogsToWordpress.txt中,的确没了crifanLib,但是还是有一些其他,可能要依赖的库:

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等库。

不过,关于PIL,我去看了看自己的

D:\tmp\dev_install_root\Python27_x64\Lib\site-packages

中的确没有,应该是重装python,导致了之前安装好的PIL没了。

所以,还是需要自己重新安装一下PIL的。

12.关于安装PIL的过程,详见:

【记录】下载和安装Python的第三方图像处理的库:PIL(Python Imaging Library)

13.然后再去

D:\tmp\dev_install_root\Python27_x64\Lib\site-packages

确认一下,果然有了PIL了。

然后此处,删掉旧的,重新执行一次:

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>

虽然结果警告中,也还是有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模块内部的一些小问题罢了,不理会。

生成的exe,的确又变大了,4748KB:

13.去运行现在的最新的BlogsToWordpress.exe,看看效果如何。

果然是可以,如期望的一样,去执行了:

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.如果脚本运行出错,请务必把上述(1)从脚本开始运行到上述所打印出来的系统信息(2)出错时候的相关信息(3)脚本所生成的BlogsToWordpress.log文件,通过复制粘贴、截图、附件等方式
LINE 1600 : INFO       发送至admin(at)crifan.com或跟帖(下面有地址)回复,否则如果没有足够的错误相关信息,我就是想帮你解决问题,也没法帮啊!
LINE 1600 : INFO     2.如对此脚本使用有任何疑问,请输入-h参数以获得相应的参数说明。
LINE 1600 : INFO     3.关于本程序详细的使用说明和更多相关信息,请参考:
LINE 1600 : INFO       BlogsToWordPress:将百度空间(新版和旧版),网易163,新浪Sina,QQ空间,人人网,CSDN,搜狐Sohu,博客大巴Blogbus,天涯博客,点点轻博客等博客搬家到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>

加上对应参数,再试试:

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)
...

的确就是可以正常执行了。

剩下的,就是要拿到别的windows平台上,多测试测试,是否都正常。

14.接着打算再去试试,添加icon图标的事情。

参考官网的参数解释

-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.

去运行:

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

可以看到,其自动会把icon添加到当前已有的exe中,然后可以看到对应的,带图标的exe的效果:

总结

PyInstaller,的确非常好用啊。感谢作者们。

简单总结其使用方法:

生成单一的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

添加必要的搜索路径,且带图标:

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是你的项目名)

中,是否缺少了必要的模块。

如果有缺少的,那么去如上所述,添加必要的搜素路径,使得pyinstaller在运行时,可以找到对应的模块并集成进来。

2.此处我这里没有UPX,暂时没去折腾。

估计是用UPX去压缩,压缩后所生成的exe文件的大小,会小得多。

(0)

相关推荐

  • Python打包方法Pyinstaller的使用

    Python是一个脚本语言,被解释器解释执行.它的发布方式: .py文件:对于开源项目或者源码没那么重要的,直接提供源码,需要使用者自行安装Python并且安装依赖的各种库.(Python官方的各种安装包就是这样做的) .pyc文件:有些公司或个人因为机密或者各种原因,不愿意源码被运行者看到,可以使用pyc文件发布,pyc文件是Python解释器可以识别的二进制码,故发布后也是跨平台的,需要使用者安装相应版本的Python和依赖库. 可执行文件:对于非码农用户或者一些小白用户,你让他装个Pyth

  • python-pyinstaller、打包后获取路径的实例

    使用pyinstaller可以把.py文件打包为.exe可执行文件,命令为: pyinstaller hello.py 打包后有两个文件夹,一个是dist,另外一个是build,可执行文件在dist文件夹里面,但是会有许多依赖是独立文件存在 pyinstaller -F hello.py 使用-F参数后,打包的可执行文件是一个整体,只有一个.exe文件. 获取文件路径的方式有四种,可以在打包成exe文件后,获取.exe文件的当前路径 import sys import os print(sys.

  • python pyinstaller打包exe报错的解决方法

    今天用python 使用pyinstaller打包exe出现错误 环境pyqt5 + python3.6 32位 在导入pyqt5包之前加上如下代码 import sys import os if hasattr(sys, 'frozen'): os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH'] from PyQt5.QtWidgets import QApplication, QMainWindow from py

  • 详解pyinstaller selenium python3 chrome打包问题

    今天打包selenium一个简单的请求,打完包本机运行exe没有问题,换台机器就闪退,非常蛋疼找了半天原因. 下面简述下,防止踩坑,如果闪退十有八九是浏览器版本跟浏览器插件对不上. 首先安装pyinstaller pip install pyinstaller 然后进入要打包的py文件目录 然后pyinstaller tomcat.py 这种打包方式有很多文件,不太美观 第二种打包方式:pyinstaller -F tomcat.py 下面就是重点,我之前忘记把浏览器插件复制到.exe文件目录所

  • python学习笔记--将python源文件打包成exe文件(pyinstaller)

    pyinstaller 库的使用 PyInstaller是一个十分有用的第三方库,它能够在Windows.Linux.Mac OS X 等操作系统下将 Python 源文件打包,通过对源文件打包,Python 程序可以在没有安装 Python 的环境中运行,也可以作为一个独立文件方便传递和管理.PyInstaller 需要在命令行(控制台)下用pip 工具安装,如下: :\>pip install pyinstaller 或 :\>pip3 install pyinstaller PyInst

  • 利用pyinstaller或virtualenv将python程序打包详解

    运行环境: CentOS6.5_x64 Python版本 : 2.6 使用pyinstaller打包 pyinstaller可以将python程序打包成二进制文件,打包后的文件在没有python的环境中也可以执行(但要有相关底层libc相关so文件).pyinstaller支持将python程序打包成单个文件,它所做的只是将文本转换成二进制,并不能给python提速,相反还会影响打包后程序的运行速度. 安装pyinstaller 官方网址:http://www.pyinstaller.org/

  • Python程序打包工具py2exe和PyInstaller详解

    前言 通常执行 python 程序要有相应的 Python 环境,但某些特定场景下,我们可能并不愿意这么麻烦的去配置这些环境(比如将写好的脚本发给客户进行操作),如果可以提前将程序打包成 Windows平台的 .exe 文件或者是Linux下的 .sh 脚本,那么使用起来就会方便很多,py2exe 和 PyInstaller 这两款工具都是干这么个事的,下面以 hello.py 脚本(代码内容如下)为例进行介绍. age = input("How old are you?\n") pr

  • 用PyInstaller把Python代码打包成单个独立的exe可执行文件

    之前就想要把自己的BlogsToWordpress打开成exe了.一直没去弄. 又看到有人提到python打开成exe的问题. 所以打算现在就去试试. 注:此处之所有选用BlogsToWordpress,是因为此python脚本够复杂,依赖的模块够多. 如果这个都搞定了,那么其他单个的python文件,和小python项目的打包,就更不成问题了. 1.先去找找,目前主流有哪几种方法. 找到几个名字 cx_Freeze PyInstaller py2exe 2.关于py2exe和PyInstall

  • 将Python代码打包成.exe可执行文件的完整步骤

    前言 有时候我们需要将自己写的代码打包成exe文件,给别人使用需要怎么办呢?以下将讲解Python代码如何打包成.exe文件. 1. 下载pyinstaller PyInstaller是一个十分有用的第三方库,它能够在Windows.Linux. Mac OS X 等操作系统下将 Python 源文件打包,通过对源文件打包, Python 程序可以在没有安装 Python 的环境中运行,也可以作为一个 独立文件方便传递和管理. 因为Python中有很多三方包,我们想要这些三方包也包含在里面就需要

  • 通过Py2exe将自己的python程序打包成.exe/.app的方法

    Windows 10 x64 macOS Sierra 10.12.4 Python 2.7 准备好装哔~了么,来吧,做个真正意义上的绿色小软件 Win下发布应用 起因 今天实验室同学看到我的乞丐版二输入规则器,他挺感兴趣的,也想要玩玩,但是他没有装python的环境,总不能让他一直玩我电脑吧,所以想到了将程序打包成exe,直接运行!想法一出来,根本挡不住啊,说干就干,先百度python打包exe,一大堆答案,我整理了一下,大概有Py2exe和pyinstaller两种,但是,我给你看张图 这是

  • Windows下将Python文件打包成.EXE可执行文件的方法

    在使用Python做开发的时候,时不时会给自己编写了一些小工具辅助自己的工作,但是由于开发依赖环境问题,多数只能在自己电脑上运行,拿到其它电脑后就没法运行了.这显得很不方便,不符合我们的初衷,那么有没有一种什么办法可以使我们编写好的程序,可以直接在各种windows下运行的呢? 答案是:有的,说到windows大家都能想到( .exe )这个东西吧!没错,就是把Python编写的代码打包成可执行的 exe 文件,直接在系统上运行,这个问题不久完美解决了吗? 下面就来讲讲如何实现,具体如下: 安装

  • 如何将Python脚本打包成exe应用程序介绍

    目录 前言 安装Pyinstaller 将脚本打包成exe应用程序 进阶:消除命令窗口.自定义图标 总结 前言 我们有时候会编写Python脚本来辅助我们执行一些重复的操作.但是这些脚本在实际使用中会有一些不方便: 我们通常需要进入终端或者IDE中来运行脚本(当然,有办法可以实现双击脚本文件直接运行,但这不在今天的讨论范围内). 如果把脚本迁移至其他电脑上,那么Python环境变化,比如新电脑上没有安装Python,或者缺乏该脚本所调用的包等,脚本有很大概率无法正常运行. 这时候,我们可以将脚本

  • 使用PyInstaller库把Python程序打包成exe

    一.pyinstaller简介 Python是一个脚本语言,被解释器解释执行.它的发布方式: .py文件:对于开源项目或者源码没那么重要的,直接提供源码,需要使用者自行安装Python并且安装依赖的各种库.(Python官方的各种安装包就是这样做的) .pyc文件:有些公司或个人因为机密或者各种原因,不愿意源码被运行者看到,可以使用pyc文件发布,pyc文件是Python解释器可以识别的二进制码,故发布后也是跨平台的,需要使用者安装相应版本的Python和依赖库. 可执行文件:对于非码农用户或者

  • python3.7将代码打包成exe程序并添加图标的方法

    1.环境 1.python 3.7 2.pyinstaller 2.下载方式: 2.1 python安装(略) 2.2 安装pyinstaller 打开DOS窗口输入以下命令: pip install pyinstaller 3.打包exe程序 打开DOS窗口,输入命令:pyinstaller -F -w *.py(星号是.py的全部路径) pyinstaller -F -w G:\automation\test.py (备注:-F是打包单一文件,-w是运行时不弹出黑窗口) 如下图显示,打包成功

  • pyinstaller还原python代码过程图解

    这篇文章主要介绍了pyinstaller还原python代码过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 pyinstaller 的作用就是将python打包成对应平台的可执行文件.一般这种可执行文件的体积都比较大. 我们可以先通过逆向软件查看一下具体信息 查看字符串信息 只要有诸如以上的字符串 就说明这个可执行文件有很大程度上是通过pyinstaller打包的 解密方法有两个 1. pyinstxtractor.py 方法很简单 直

  • Python项目打包成二进制的方法

    Python项目打包 python本身是一种脚本语音,发布的话,直接发布源代码就可以了,但是,可能有些公司并不想发布源代码,那么,就涉及到打包了,网上有很的打包教程,其实我也没有认真去研究,因为我只想简单点,所以,我打算直接编译成pyc二进制文件来发布,就可以了. 问题 编译成二进制文件(*.pyc)之后,文件名都变了,模块之间怎么引用? 网上的例子,大都是对单个文件编译的介绍,对整个目录编译的话,也都是输出到相应的文件夹下,需要单独抽取出来,发布. 解决问题 一般编译之后的文件命名为:比如我的

  • 将python项目打包成exe与安装包的全过程

    目录 一.打包Flask项目 1.1自己写个Flask 2.2 下载pyinstaller 2.3 进入到项目路径下,执行 2.4 运行exe,测试 二.使用nsis把文件夹打包成windows的安装包 2.1 下载安装nsis 2.2把dist文件夹下的run文件夹压缩成zip 2.3使用nsis把压缩包,做成windows安装文件 总结 一.打包Flask项目 1.1自己写个Flask 2.2 下载pyinstaller pip install pyinstaller 可选参数 示例 说明

随机推荐