最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Python crifan 42460浏览 0评论

之前就想要把自己的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文件夹:

generated project subdir

其下,也有对应的:

build dist spec

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

has generated exe

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

dist include dll and exe and pyd

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

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等文件:

build include many toc pkg

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

dist include one exe file

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

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了:

exe larger 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:

more bigger 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的效果:

exe added icon

 

总结

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文件的大小,会小得多。

转载请注明:在路上 » 【记录】用PyInstaller把Python代码打包成单个独立的exe可执行文件

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (27)

  1. 麻烦问一个问题,我的项目里有一个config.py的配置文件,内容基本是json格式的,可是打包一起打进去了。配置文件没法动态更改了,这怎么破
    JasonWong6年前 (2018-01-19)回复
  2. missing module named 需要指定site-packages的位置,有用,点赞!
    RunhwGuo7年前 (2017-08-08)回复
  3. 在代码中使用了cx_oracle,运行调试都正常,但是打包后,就提示无法获取oracle句柄了,这个cx_oracle是不是需要特殊处理啊???
    zhoujm7年前 (2016-11-03)回复
    • 你好,你的包含cx_Oracle打包进去的问题处理好了吗?我是生成的exe在自己电脑上运行没有问题,但是一拿到其他人电脑上就报错:UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 94-95: invalid continuation byte
      酷酷的洋7年前 (2017-08-03)回复
  4. 您好作者, 我按上面的教程首次编译时怎么报很多库不存在呢: 41 INFO: Testing for ability to set icons, version resources... 55 INFO: ... resource update available 71 INFO: UPX is not available. 001 INFO: checking Analysis 001 INFO: building because inputs changed 001 INFO: running Analysis out00-Analysis.toc 001 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 080 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 080 WARNING: Assembly not found 080 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 095 ERROR: lib not found: MSVCR90.dll dependency of C:\Python27\python.exe 158 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 158 WARNING: Assembly not found 158 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 236 ERROR: lib not found: MSVCR90.dll dependency of C:\Windows\system32\python27.dll 236 INFO: Analyzing E:\pyscript\pyinstaller-2.0\support\_pyi_bootstrap.py 069 INFO: Analyzing E:\pyscript\pyinstaller-2.0\PyInstaller\loader\archive.py 148 INFO: Analyzing E:\pyscript\pyinstaller-2.0\PyInstaller\loader\carchive.py 225 INFO: Analyzing E:\pyscript\pyinstaller-2.0\PyInstaller\loader\iu.py 240 INFO: Analyzing deamon.py 521 INFO: Hidden import 'encodings' has been found otherwise 521 INFO: Looking for run-time hooks 521 INFO: Analyzing rthook E:\pyscript\pyinstaller-2.0\support/rthooks/pyi_rth_encodings.py 615 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 615 WARNING: Assembly not found 616 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 648 ERROR: lib not found: MSVCR90.dll dependency of C:\Python27\DLLs\select.pyd 710 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 710 WARNING: Assembly not found 710 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 741 ERROR: lib not found: MSVCR90.dll dependency of C:\Python27\DLLs\unicodedata.pyd 789 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 789 WARNING: Assembly not found 789 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 835 ERROR: lib not found: MSVCR90.dll dependency of C:\Python27\DLLs\_hashlib.pyd 898 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 898 WARNING: Assembly not found 898 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 929 ERROR: lib not found: MSVCR90.dll dependency of C:\Python27\DLLs\bz2.pyd 991 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 991 WARNING: Assembly not found 991 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 053 ERROR: lib not found: MSVCR90.dll dependency of C:\Python27\DLLs\_ssl.pyd 100 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 100 WARNING: Assembly not found 100 ERROR: Assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none not found 148 ERROR: lib not found: MSVCR90.dll dependency of C:\Python27\DLLs\_socket.pyd 794 INFO: Warnings written to E:\pyscript\pyinstaller-2.0\deamon\build\pyi.win32\deamon\warndeamon.txt
    黄生8年前 (2016-07-26)回复
  5. 用python写了一个项目的自动化测试,用你提供的方法终于弄成功了,虽然研究了好几天,太感谢了。
    Hedy8年前 (2016-06-23)回复
    • 我还有个问题,,生成的exe是在dist文件下中,但每次运行的时候太麻烦,您知道怎么生成exe在指定的目录下吗?
      Hedy8年前 (2016-06-23)回复
  6. 根据你的方法生成了单个exe,成功,非常感谢博主,执行的时候有DOS命令窗口,然后百度,加上-w参数,没有窗口了,可是为什么exe执行不了了呢,没有加-w参数的时候都是可以运行的,为什么加了参数后运行不起呢
    intC8年前 (2016-03-27)回复
    • 加参数--noconsole都是,什么错都没报,好奇怪
      intC8年前 (2016-03-27)回复
  7. 写的很清楚,谢了楼主先~~~
    ximian8年前 (2016-02-14)回复
  8. 你好,我按照你的方式生成的exe,双击运行一闪而过,在cmd下面进入到exe所在目录运行exe正常,这是为什么呢?我需要给别人使用,直接双击也能有正常结果。
    nixiaoli8年前 (2015-12-14)回复
  9. 想问一下,我用pygame做了个游戏,也成功生成了EXE文件,但是运行不了,我想是因为图片文件没有被打包进去,那图片应该怎样才能与py文件一起打包成EXE文件?网上找了很久都找不到,跪求解答
    ace8年前 (2015-11-24)回复
  10. E:\pyinstaller>python pyinstaller.py -F -p E:\python\Lib\xml\sax;E:\python\reque sts\packages\urllib3;E:\python\Lib;E:\python\requests\packages\urllib3\contrib;E :\python\requests\packages\urllib3\packages\ssl_match_hostname;E:\python\request s\packages\urllib3\packages;E:\python\simplejson; google2.py 楼主我加上-p参数也没用是怎么回事? 还是提示模块没加载 W: no module named org (delayed import by xml.sax) W: no module named http (top-level import by requests.packages.urllib3.connection) W: no module named readline (delayed import by pdb) 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 ndg (top-level import by requests.packages.urllib3.contrib.pyopenssl) 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 _scproxy (conditional import by urllib) W: no module named logging.NullHandler (top-level import by requests.packages.urllib3) W: no module named backports (conditional import by requests.packages.urllib3.packages.ssl_match_hostname) W: no module named MacOS (delayed import by platform) W: no module named requests.packages.urllib3.packages.ssl_match_hostname.CertificateError (top-level import by __main__) W: no module named AES (delayed, conditional import by archive) W: no module named builtins (conditional import by requests.packages.urllib3.packages.six) W: no module named simplejson._speedups (delayed import by simplejson.scanner) W: no module named importlib.reload (conditional import by simplejson.compat) W: no module named pyasn1 (top-level import by requests.packages.urllib3.contrib.pyopenssl) 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 java (delayed import by platform) W: no module named cl (delayed import by aifc) W: no module named http (conditional import by requests.compat) 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 _speedups (delayed import by __main__) W: no module named logging.NullHandler (top-level import by requests) W: no module named OpenSSL (top-level import by requests.packages.urllib3.contrib.pyopenssl) W: no module named _emx_link (conditional import by os) W: no module named posix (conditional import by os) W: no module named ctypes.cdll (delayed import by ctypes.util) W: no module named rourl2path (conditional import by urllib) W: no module named __version__ (top-level import by __main__) W: no module named vms_lib (delayed, conditional import by platform) W: no module named queue (top-level import by requests.packages.urllib3.connectionpool) W: no module named requests.packages.urllib3.packages.ssl_match_hostname.match_hostname (top-level import by __main__) 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__)
    xss9年前 (2015-01-11)回复
  11. 你好,我按照你的方法打包我一个webpy的应用,webpy是python的一个第三方包,一直不能成功,很多warning,不知道什么原因,可以帮帮我么
    赵鹏飞9年前 (2014-11-08)回复
    • 那去加入我的技术QQ群:104028266 吧
      crifan9年前 (2014-11-10)回复
  12. 谢谢,佩服,继续加油哦
    妙如10年前 (2013-12-12)回复
  13. 我写了一个带有ibm_db模块的 db2连接的脚本。生成exe的时候 不会弄了。。。 需要导入第三方的模块,我按着您的,没有成功。。请求帮助~~~
    callable11年前 (2013-10-30)回复
    • https://groups.google.com/forum/#!msg/ibm_db/5QHuhxpPEGs/Mk9ZX_JS8ZwJ
      callable11年前 (2013-10-30)回复
  14. 警告信息: W: no module named arcpy.geoprocessing.gp (top-level import by arcpy) W: no module named org (delayed import by xml.sax) W: no module named xml.dom.XML_NAMESPACE (delayed import by xml.dom.pulldom) W: no module named _dummy_threading (top-level import by dummy_threading) W: no module named arcpy.arcobjects._BaseArcObject (delayed import by __main__) W: no module named cl (delayed, conditional import by aifc) W: no module named xml.dom.XMLNS_NAMESPACE (top-level import by xml.dom.expatbuilder) W: no module named arcpy.geoprocessing.env (top-level import by arcpy) W: no module named pwd (delayed, conditional import by posixpath) W: no module named org (top-level import by pickle) W: no module named posix (delayed, conditional import by __main__) W: no module named xml.dom.XMLNS_NAMESPACE (top-level import by xml.dom.minidom) W: no module named fcntl (conditional import by subprocess) W: no module named _scproxy (conditional import by urllib) W: no module named arcpy.Extent (top-level import by arcpy.sa) W: no module named java (conditional import by xml.sax._exceptions) W: no module named arcpy.sa.Raster (top-level import by arcpy) W: no module named readline (delayed import by pdb) W: no module named CreateObject (delayed import by __main__) 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 gp (top-level import by __main__) W: no module named termios (top-level import by getpass) W: no module named xml.dom.EMPTY_NAMESPACE (top-level import by xml.dom.expatbuilder) W: no module named org (top-level import by copy) W: no module named fcntl (top-level import by tempfile) W: no module named arcpy.Point (top-level import by arcpy.sa) W: no module named arcpy.gp (top-level import by arcpy.sa.Utils) W: no module named readline (delayed, conditional import by cmd) W: no module named EasyDialogs (conditional import by getpass) W: no module named cl (delayed import by aifc) W: no module named arcpy.arcobjects.Result (delayed import by __main__) W: no module named xmltok (top-level import by pyexpat) W: no module named Crypt (delayed, conditional import by __main__) W: no module named xml.dom.EMPTY_PREFIX (top-level import by xml.dom.minidom) W: no module named arcpy.arcobjects.Result (top-level import by arcpy._ga) W: no module named AES (delayed, conditional import by __main__) W: no module named posix (conditional import by os) W: no module named xmlparse (top-level import by pyexpat) W: no module named xml.dom.DOMImplementation (top-level import by xml.dom.domreg) W: no module named rourl2path (conditional import by urllib) W: no module named env (top-level import by __main__) W: no module named xml.dom.EMPTY_NAMESPACE (top-level import by xml.dom.minidom) W: no module named arcpy.Extent (top-level import by arcpy.sa.Utils) W: no module named xml.dom.EMPTY_PREFIX (top-level import by xml.dom.expatbuilder) W: no module named SOCKS (top-level import by ftplib) W: no module named _xmlplus (top-level import by xml) W: no module named production (top-level import by arcpy) W: no module named mobile (top-level import by arcpy) W: delayed exec statement detected at line 0 - bdb (C:\Python26\ArcGIS10.0\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\ArcGIS10.0\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\ArcGIS10.0\lib\bdb.pyc) W: delayed __import__ hack detected at line 0 - optparse (C:\Python26\ArcGIS10.0\lib\optparse.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C:\Python26\ArcGIS10.0\lib\doctest.pyc) W: delayed exec statement detected at line 0 - doctest (C:\Python26\ArcGIS10.0\lib\doctest.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C:\Python26\ArcGIS10.0\lib\doctest.pyc) W: __all__ is built strangely at line 0 - tokenize (C:\Python26\ArcGIS10.0\lib\tokenize.pyc) W: delayed __import__ hack detected at line 0 - pickle (C:\Python26\ArcGIS10.0\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - pickle (C:\Python26\ArcGIS10.0\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - arcpy.toolbox_code (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\toolbox_code.pyc) W: delayed conditional __import__ hack detected at line 0 - arcpy.toolbox_code (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\toolbox_code.pyc) W: delayed eval hack detected at line 0 - arcpy.toolbox_code (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\toolbox_code.pyc) W: delayed __import__ hack detected at line 0 - encodings (C:\Python26\ArcGIS10.0\lib\encodings\__init__.pyc) W: __all__ is built strangely at line 0 - arcpy.ga (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\ga.pyc) W: __all__ is built strangely at line 0 - dummy_threading (C:\Python26\ArcGIS10.0\lib\dummy_threading.pyc) W: __all__ is built strangely at line 0 - dis (C:\Python26\ArcGIS10.0\lib\dis.pyc) W: __all__ is built strangely at line 0 - arcpy._management (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\_management.pyc) W: top-level exec statement detected at line 0 - hashlib (C:\Python26\ArcGIS10.0\lib\hashlib.pyc) W: top-level conditional exec statement detected at line 0 - hashlib (C:\Python26\ArcGIS10.0\lib\hashlib.pyc) W: delayed conditional eval hack detected at line 0 - warnings (C:\Python26\ArcGIS10.0\lib\warnings.pyc) W: delayed conditional __import__ hack detected at line 0 - warnings (C:\Python26\ArcGIS10.0\lib\warnings.pyc) W: __all__ is built strangely at line 0 - arcpy.management (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\management.pyc) W: delayed __import__ hack detected at line 0 - email (C:\Python26\ArcGIS10.0\lib\email\__init__.pyc) W: delayed conditional __import__ hack detected at line 0 - xml.dom.domreg (C:\Python26\ArcGIS10.0\lib\xml\dom\domreg.pyc) W: delayed exec statement detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed conditional exec statement detected at line 0 - iu (C:\pyinstaller2\PyInstaller\loader\iu.pyc) W: delayed conditional exec statement detected at line 0 - iu (C:\pyinstaller2\PyInstaller\loader\iu.pyc) W: __all__ is built strangely at line 0 - arcpy.sa (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\sa\__init__.pyc) W: __all__ is built strangely at line 0 - arcpy.sa (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\sa\__init__.pyc) W: __all__ is built strangely at line 0 - arcpy.sa (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\sa\__init__.pyc) W: __all__ is built strangely at line 0 - collections (C:\Python26\ArcGIS10.0\lib\collections.pyc) W: delayed exec statement detected at line 0 - collections (C:\Python26\ArcGIS10.0\lib\collections.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\ArcGIS10.0\lib\unittest.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\ArcGIS10.0\lib\unittest.pyc) W: delayed exec statement detected at line 0 - socket (C:\Python26\ArcGIS10.0\lib\socket.pyc) W: delayed eval hack detected at line 0 - os (C:\Python26\ArcGIS10.0\lib\os.pyc) W: __all__ is built strangely at line 0 - __future__ (C:\Python26\ArcGIS10.0\lib\__future__.pyc) W: delayed __import__ hack detected at line 0 - xml.sax (C:\Python26\ArcGIS10.0\lib\xml\sax\__init__.pyc) W: delayed eval hack detected at line 0 - gettext (C:\Python26\ArcGIS10.0\lib\gettext.pyc) 运行的命令: W: no module named arcpy.geoprocessing.gp (top-level import by arcpy) W: no module named org (delayed import by xml.sax) W: no module named xml.dom.XML_NAMESPACE (delayed import by xml.dom.pulldom) W: no module named _dummy_threading (top-level import by dummy_threading) W: no module named arcpy.arcobjects._BaseArcObject (delayed import by __main__) W: no module named cl (delayed, conditional import by aifc) W: no module named xml.dom.XMLNS_NAMESPACE (top-level import by xml.dom.expatbuilder) W: no module named arcpy.geoprocessing.env (top-level import by arcpy) W: no module named pwd (delayed, conditional import by posixpath) W: no module named org (top-level import by pickle) W: no module named posix (delayed, conditional import by __main__) W: no module named xml.dom.XMLNS_NAMESPACE (top-level import by xml.dom.minidom) W: no module named fcntl (conditional import by subprocess) W: no module named _scproxy (conditional import by urllib) W: no module named arcpy.Extent (top-level import by arcpy.sa) W: no module named java (conditional import by xml.sax._exceptions) W: no module named arcpy.sa.Raster (top-level import by arcpy) W: no module named readline (delayed import by pdb) W: no module named CreateObject (delayed import by __main__) 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 gp (top-level import by __main__) W: no module named termios (top-level import by getpass) W: no module named xml.dom.EMPTY_NAMESPACE (top-level import by xml.dom.expatbuilder) W: no module named org (top-level import by copy) W: no module named fcntl (top-level import by tempfile) W: no module named arcpy.Point (top-level import by arcpy.sa) W: no module named arcpy.gp (top-level import by arcpy.sa.Utils) W: no module named readline (delayed, conditional import by cmd) W: no module named EasyDialogs (conditional import by getpass) W: no module named cl (delayed import by aifc) W: no module named arcpy.arcobjects.Result (delayed import by __main__) W: no module named xmltok (top-level import by pyexpat) W: no module named Crypt (delayed, conditional import by __main__) W: no module named xml.dom.EMPTY_PREFIX (top-level import by xml.dom.minidom) W: no module named arcpy.arcobjects.Result (top-level import by arcpy._ga) W: no module named AES (delayed, conditional import by __main__) W: no module named posix (conditional import by os) W: no module named xmlparse (top-level import by pyexpat) W: no module named xml.dom.DOMImplementation (top-level import by xml.dom.domreg) W: no module named rourl2path (conditional import by urllib) W: no module named env (top-level import by __main__) W: no module named xml.dom.EMPTY_NAMESPACE (top-level import by xml.dom.minidom) W: no module named arcpy.Extent (top-level import by arcpy.sa.Utils) W: no module named xml.dom.EMPTY_PREFIX (top-level import by xml.dom.expatbuilder) W: no module named SOCKS (top-level import by ftplib) W: no module named _xmlplus (top-level import by xml) W: no module named production (top-level import by arcpy) W: no module named mobile (top-level import by arcpy) W: delayed exec statement detected at line 0 - bdb (C:\Python26\ArcGIS10.0\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\ArcGIS10.0\lib\bdb.pyc) W: delayed eval hack detected at line 0 - bdb (C:\Python26\ArcGIS10.0\lib\bdb.pyc) W: delayed __import__ hack detected at line 0 - optparse (C:\Python26\ArcGIS10.0\lib\optparse.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C:\Python26\ArcGIS10.0\lib\doctest.pyc) W: delayed exec statement detected at line 0 - doctest (C:\Python26\ArcGIS10.0\lib\doctest.pyc) W: delayed conditional __import__ hack detected at line 0 - doctest (C:\Python26\ArcGIS10.0\lib\doctest.pyc) W: __all__ is built strangely at line 0 - tokenize (C:\Python26\ArcGIS10.0\lib\tokenize.pyc) W: delayed __import__ hack detected at line 0 - pickle (C:\Python26\ArcGIS10.0\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - pickle (C:\Python26\ArcGIS10.0\lib\pickle.pyc) W: delayed __import__ hack detected at line 0 - arcpy.toolbox_code (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\toolbox_code.pyc) W: delayed conditional __import__ hack detected at line 0 - arcpy.toolbox_code (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\toolbox_code.pyc) W: delayed eval hack detected at line 0 - arcpy.toolbox_code (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\toolbox_code.pyc) W: delayed __import__ hack detected at line 0 - encodings (C:\Python26\ArcGIS10.0\lib\encodings\__init__.pyc) W: __all__ is built strangely at line 0 - arcpy.ga (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\ga.pyc) W: __all__ is built strangely at line 0 - dummy_threading (C:\Python26\ArcGIS10.0\lib\dummy_threading.pyc) W: __all__ is built strangely at line 0 - dis (C:\Python26\ArcGIS10.0\lib\dis.pyc) W: __all__ is built strangely at line 0 - arcpy._management (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\_management.pyc) W: top-level exec statement detected at line 0 - hashlib (C:\Python26\ArcGIS10.0\lib\hashlib.pyc) W: top-level conditional exec statement detected at line 0 - hashlib (C:\Python26\ArcGIS10.0\lib\hashlib.pyc) W: delayed conditional eval hack detected at line 0 - warnings (C:\Python26\ArcGIS10.0\lib\warnings.pyc) W: delayed conditional __import__ hack detected at line 0 - warnings (C:\Python26\ArcGIS10.0\lib\warnings.pyc) W: __all__ is built strangely at line 0 - arcpy.management (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\management.pyc) W: delayed __import__ hack detected at line 0 - email (C:\Python26\ArcGIS10.0\lib\email\__init__.pyc) W: delayed conditional __import__ hack detected at line 0 - xml.dom.domreg (C:\Python26\ArcGIS10.0\lib\xml\dom\domreg.pyc) W: delayed exec statement detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed conditional eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed eval hack detected at line 0 - pdb (C:\Python26\ArcGIS10.0\lib\pdb.pyc) W: delayed conditional exec statement detected at line 0 - iu (C:\pyinstaller2\PyInstaller\loader\iu.pyc) W: delayed conditional exec statement detected at line 0 - iu (C:\pyinstaller2\PyInstaller\loader\iu.pyc) W: __all__ is built strangely at line 0 - arcpy.sa (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\sa\__init__.pyc) W: __all__ is built strangely at line 0 - arcpy.sa (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\sa\__init__.pyc) W: __all__ is built strangely at line 0 - arcpy.sa (D:\Program Files\ArcGis\Desktop10.0\arcpy\arcpy\sa\__init__.pyc) W: __all__ is built strangely at line 0 - collections (C:\Python26\ArcGIS10.0\lib\collections.pyc) W: delayed exec statement detected at line 0 - collections (C:\Python26\ArcGIS10.0\lib\collections.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\ArcGIS10.0\lib\unittest.pyc) W: delayed conditional __import__ hack detected at line 0 - unittest (C:\Python26\ArcGIS10.0\lib\unittest.pyc) W: delayed exec statement detected at line 0 - socket (C:\Python26\ArcGIS10.0\lib\socket.pyc) W: delayed eval hack detected at line 0 - os (C:\Python26\ArcGIS10.0\lib\os.pyc) W: __all__ is built strangely at line 0 - __future__ (C:\Python26\ArcGIS10.0\lib\__future__.pyc) W: delayed __import__ hack detected at line 0 - xml.sax (C:\Python26\ArcGIS10.0\lib\xml\sax\__init__.pyc) W: delayed eval hack detected at line 0 - gettext (C:\Python26\ArcGIS10.0\lib\gettext.pyc) 运行的命令及显示内容: Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\Administrator>cd.. C:\Users>cd.. C:\>cd C:\pyinstaller2 C:\pyinstaller2>pyinstaller.py -F C:\scripts\main.py 62 INFO: wrote C:\pyinstaller2\main\main.spec 92 INFO: Testing for ability to set icons, version resources... 92 INFO: ... resource update available 229 INFO: UPX is available. 1856 INFO: checking Analysis 1856 INFO: building Analysis because out00-Analysis.toc non existent 1856 INFO: running Analysis out00-Analysis.toc 1856 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable 1936 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21 022.8_none ... 1936 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc 8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91.manifest 1966 INFO: Searching for file msvcr90.dll 1966 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.21022.8_none_bcb86ed6ac711f91\msvcr90.dll 1966 INFO: Searching for file msvcp90.dll 1966 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.21022.8_none_bcb86ed6ac711f91\msvcp90.dll 1976 INFO: Searching for file msvcm90.dll 1976 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.21022.8_none_bcb86ed6ac711f91\msvcm90.dll 2536 INFO: Analyzing C:\pyinstaller2\support\_pyi_bootstrap.py 4072 INFO: Analyzing C:\pyinstaller2\PyInstaller\loader\archive.py 4314 INFO: Analyzing C:\pyinstaller2\PyInstaller\loader\carchive.py 4564 INFO: Analyzing C:\pyinstaller2\PyInstaller\loader\iu.py 4634 INFO: Analyzing C:\scripts\main.py 7886 INFO: Hidden import 'encodings' has been found otherwise 7886 INFO: Looking for run-time hooks 7886 INFO: Analyzing rthook C:\pyinstaller2\support/rthooks/pyi_rth_encodings.py 9186 INFO: Adding Microsoft.VC80.CRT to dependent assemblies of final executable 9256 INFO: Searching for assembly x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50 727.762_none ... 9256 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc80.crt_1fc 8b3b9a1e18e3b_8.0.50727.762_none_10b2f55f9bffb8f8.manifest 9266 INFO: Searching for file msvcr80.dll 9266 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_ 8.0.50727.762_none_10b2f55f9bffb8f8\msvcr80.dll 9266 INFO: Searching for file msvcp80.dll 9276 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_ 8.0.50727.762_none_10b2f55f9bffb8f8\msvcp80.dll 9276 INFO: Searching for file msvcm80.dll 9276 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_ 8.0.50727.762_none_10b2f55f9bffb8f8\msvcm80.dll 10786 ERROR: lib not found: gdiplus.dll dependency of D:\Program Files\ArcGis\De sktop10.0\bin\LayerLib.dll 11940 ERROR: lib not found: gdiplus.dll dependency of D:\Program Files\ArcGis\De sktop10.0\bin\DisplayLib.dll 15022 INFO: Warnings written to C:\pyinstaller2\main\build\pyi.win32\main\warnma in.txt 15042 INFO: checking PYZ 15042 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing 15042 INFO: building PYZ out00-PYZ.toc 19594 INFO: checking PKG 19594 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing 19594 INFO: building PKG out00-PKG.pkg 22190 INFO: checking EXE 22190 INFO: rebuilding out00-EXE.toc because main.exe missing 22190 INFO: building EXE from out00-EXE.toc 22230 INFO: Appending archive to EXE C:\pyinstaller2\main\dist\main.exe C:\pyinstaller2>pyinstaller.py -F C:\scripts\main.py C:\pyinstaller2> C:\pyinstaller2>
    东方白玉11年前 (2013-09-17)回复
    • 1.使用 -F -p格式如何写呢? 2.如何才能找到模块的路径? 以上,烦您指教!
      东方白玉11年前 (2013-09-17)回复
      • 1.关于参数使用,我已经给出链接了: http://www.pyinstaller.org/export/v2.0/project/doc/Manual.html?format=raw#requirements 2.如果你实在看不懂英文,那么我帮你翻译: -F, --onefile 创建单个文件,即生成的单个的xxx.exe -p DIR, --paths=DIR 设置搜索路径。可以指定多个路径,中间通过分隔符(Linux下是冒号:,Windows是下是分号;)隔开。 3.示例用法的,我上面已经给出了,比如: 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 你这里,照葫芦画瓢,就可以写成: pyinstaller.py -F -p 路径1;路径2;......; C:\scripts\main.py 其中: 路径1;路径2;......; 需要替换你自己的路径。 3.如何才能找到模块的路径? (1)Python中,已经安装的第三方的模块的路径,PyInstaller应该可以自己找到的,不用你操心 Python系统中的安装的第三方的模块的路径,都是在你的python的安装路径下面的Lib\site-packages 比如我这里,Python安装路径是: D:\tmp\dev_install_root\Python27_x64 对应的,第三方路径,就是: D:\tmp\dev_install_root\Python27_x64\Lib\site-packages 但是,这些路径,只是让你知道就好,应该不需要加的 (2)其他的,你的python程序,所依赖的库的路径,需要你加上 其他的,你的python程序,所依赖的库 指的是: 你python程序代码中,所用到的,除了,前面介绍的,Python中安装的第三方模块,之前的那些库 比如,我的这里的BlogsToWordpress.py,代码中的相关代码是: import sys; sys.path.append("libs/crifan"); sys.path.append("libs/crifan/blogModules"); sys.path.append("libs/thirdparty"); 目的是为了引用我这里的相关的库: import crifanLib; import BlogNetease; import BlogBaidu; import BlogSina; import BlogQQ; import BlogRenren; import BlogCsdn; import BlogSohu; import BlogBlogbus; import BlogTianya; import BlogDiandian; 以及其所引用的各个BlogXXX中所引用到的: chardet BeautifulSoup 等模块。 所以,需要把这些对应的路径: 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 加入进来。 所以才有: 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 而对于你: 需要你自己去你的main.py中,自己看看,你用到了哪些: 除了,python的内置的库,和python中所安装的第三方库,之外的 还有哪些模块,把对应的模块的路径,加进来。 就可以了; 就是前面说的: pyinstaller.py -F -p 路径1;路径2;......; C:\scripts\main.py
        crifan11年前 (2013-09-22)回复
  15. 太感谢有您这样喜欢折腾的人了,自己折腾了两天,在网上找参考资料都没有找到一个靠谱的,虽然还没有试,不过看着感觉应该可行,现在准备按图索骥折腾一遍,再次感谢
    罗红亮11年前 (2013-07-05)回复
96 queries in 0.191 seconds, using 22.46MB memory