pyinstall :打包 .exe 文件报错AttributeError: module ‘enum‘ has no attribute ‘IntFlag‘

有疑问的地方 参考博文
一、环境搭建 Python GUI图形化小工具编程学习-- PySide2 环境搭建(一)
二、实例演示 Python GUI图形化小工具编程学习-- Demo 实例演示(二)
三、打包失败 pyinstall :打包 .exe 文件报错AttributeError: module ‘enum‘ has no attribute ‘IntFlag‘
四、pyinstaller打包有问题 pyinstaller打包 .py 文件为可执行的 .exe程序
五、打包后的.exe文件打开报错 PySide2:打开.exe文件报错:Failed to execute script

研究将 .py 文件通过 pyinstaller 打包成可执行的 .exe 文件时

pyinstaller -F --icon=pyexe.ico demo.py

出现了如下的报错信息:

	D:\PyCharm_Community\Test_GJ\Public_Method>pyinstaller  -F --icon=pyexe.ico demo.py
	60 INFO: PyInstaller: 3.3.1
	61 INFO: Python: 3.6.2
	61 INFO: Platform: Windows-10-10.0.18362-SP0
	62 INFO: wrote D:\PyCharm_Community\Test_GJ\Public_Method\demo.spec
	65 INFO: UPX is not available.
	66 INFO: Extending PYTHONPATH with paths
	['D:\\PyCharm_Community\\Test_GJ',
	 'D:\\PyCharm_Community\\Test_GJ\\Public_Method']
	67 INFO: checking Analysis
	67 INFO: Building Analysis because out00-Analysis.toc is non existent
	67 INFO: Initializing module dependency graph...
	71 INFO: Initializing module graph hooks...
	72 INFO: Analyzing base_library.zip ...
	Traceback (most recent call last):
	  File "", line 41, in 
	  File "", line 13, in walk_packages
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\pkgutil.py", line 127, in iter_modules
	    for name, ispkg in iter_importer_modules(i, prefix):
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\pkgutil.py", line 146, in _iter_file_finder_modules
	    import inspect
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\inspect.py", line 41, in 
	    import linecache
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\linecache.py", line 11, in 
	    import tokenize
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\tokenize.py", line 33, in 
	    import re
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\re.py", line 142, in 
	    class RegexFlag(enum.IntFlag):
	AttributeError: module 'enum' has no attribute 'IntFlag'
	Traceback (most recent call last):
	  File "", line 41, in 
	  File "", line 13, in walk_packages
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\pkgutil.py", line 127, in iter_modules
	    for name, ispkg in iter_importer_modules(i, prefix):
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\pkgutil.py", line 146, in _iter_file_finder_modules
	    import inspect
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\inspect.py", line 41, in 
	    import linecache
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\linecache.py", line 11, in 
	    import tokenize
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\tokenize.py", line 33, in 
	    import re
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\re.py", line 142, in 
	    class RegexFlag(enum.IntFlag):
	AttributeError: module 'enum' has no attribute 'IntFlag'
	2744 INFO: running Analysis out00-Analysis.toc
	2746 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
	  required by c:\users\86176\appdata\local\programs\python\python36\python.exe
	3121 INFO: Caching module hooks...
	3126 INFO: Analyzing D:\PyCharm_Community\Test_GJ\Public_Method\demo.py
	3280 INFO: Loading module hooks...
	3281 INFO: Loading module hook "hook-encodings.py"...
	Traceback (most recent call last):
	  File "", line 41, in 
	  File "", line 13, in walk_packages
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\pkgutil.py", line 127, in iter_modules
	    for name, ispkg in iter_importer_modules(i, prefix):
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\pkgutil.py", line 146, in _iter_file_finder_modules
	    import inspect
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\inspect.py", line 41, in 
	    import linecache
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\linecache.py", line 11, in 
	    import tokenize
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\tokenize.py", line 33, in 
	    import re
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\re.py", line 142, in 
	    class RegexFlag(enum.IntFlag):
	AttributeError: module 'enum' has no attribute 'IntFlag'
	3379 INFO: Loading module hook "hook-pydoc.py"...
	3380 INFO: Loading module hook "hook-PySide2.py"...
	3383 WARNING: Hidden import "numpy.core.multiarray" not found!
	3383 INFO: Loading module hook "hook-PySide2.QtNetwork.py"...
	Traceback (most recent call last):
	  File "", line 2, in 
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PySide2\__init__.py", line 51, in 
	    _setupQtDirectories()
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PySide2\__init__.py", line 21, in _setupQtDirectories
	    import shiboken2
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\shiboken2\__init__.py", line 10, in 
	    import zipfile
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\zipfile.py", line 8, in 
	    import re
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\re.py", line 142, in 
	    class RegexFlag(enum.IntFlag):
	AttributeError: module 'enum' has no attribute 'IntFlag'
	Traceback (most recent call last):
	  File "C:\Users\86176\AppData\Local\Programs\Python\Python36\Scripts\pyinstaller-script.py", line 11, in 
	    load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')()
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\__main__.py", line 94, in run
	    run_build(pyi_config, spec_file, **vars(args))
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
	    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main
	    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build
	    exec(text, spec_namespace)
	  File "", line 16, in 
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py", line 213, in __init__
	    self.__postinit__()
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
	    self.assemble()
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\build_main.py", line 472, in assemble
	    module_hook.post_graph()
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
	    self._load_hook_module()
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
	    self.hook_module_name, self.hook_filename)
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\compat.py", line 744, in importlib_load_source
	    return mod_loader.load_module()
	  File "", line 399, in _check_name_wrapper
	  File "", line 823, in load_module
	  File "", line 682, in load_module
	  File "", line 251, in _load_module_shim
	  File "", line 675, in _load
	  File "", line 655, in _load_unlocked
	  File "", line 678, in exec_module
	  File "", line 205, in _call_with_frames_removed
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\hooks\hook-PySide2.QtNetwork.py", line 15, in 
	    binaries = qt_plugins_binaries('bearer', namespace='PySide2')
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 65, in qt_plugins_binaries
	    pdir = qt_plugins_dir(namespace=namespace)
	  File "c:\users\86176\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 39, in qt_plugins_dir
	    raise Exception('Cannot find {0} plugin directories'.format(namespace))
	Exception: Cannot find PySide2 plugin directories

解决问题:

一、 这可能是由包Enum34引起的。因为Python3.4有一个标准库枚举模块,所以您应该卸载Enum34,因为在Python3.6中添加了Enum.Intflag,所以它不再与标准库中的枚举兼容,卸载 enum34

pip3 uninstall enum34
pyinstall :打包 .exe 文件报错AttributeError: module ‘enum‘ has no attribute ‘IntFlag‘_第1张图片

二、卸载完成后再次执行打包命令:pyinstaller -F --icon=pyexe.ico demo.py

pyinstall :打包 .exe 文件报错AttributeError: module ‘enum‘ has no attribute ‘IntFlag‘_第2张图片

方法参考原文跳转:

成功解决AttributeError: module ‘enum’ has no attribute ‘IntFlag’?

你可能感兴趣的:(python自学笔记,PySide2,exe,enum,pyinstaller)