pip install pyinstaller
然后 对一个python 文件进行操作:
pyinstaller -F hello.py
会在dist目录下产生 hello.exe
但是若你的源文件目录包含一个 operand.py 的文件的话,就会出来很多的bug,这是由于这个·operand.py和python内部的文件同名了,而首先使用你的目录的operand.py了。把这个文件改个名就行了。
186 INFO: PyInstaller: 3.3.1
186 INFO: Python: 3.6.5rc1
186 INFO: Platform: Windows-10-10.0.16299-SP0
186 INFO: wrote H:\python\hello.spec
186 INFO: UPX is not available.
186 INFO: Extending PYTHONPATH with paths
['H:\\python', 'H:\\python']
186 INFO: checking Analysis
186 INFO: Building Analysis because out00-Analysis.toc is non existent
186 INFO: Initializing module dependency graph...
202 INFO: Initializing module graph hooks...
202 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
File "
File "E:\Program Files (x86)\python\lib\pkgutil.py", line 3, in
from collections import namedtuple
File "E:\Program Files (x86)\python\lib\collections\__init__.py", line 26, in
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'
Traceback (most recent call last):
File "
File "E:\Program Files (x86)\python\lib\pkgutil.py", line 3, in
from collections import namedtuple
File "E:\Program Files (x86)\python\lib\collections\__init__.py", line 26, in
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'
Traceback (most recent call last):
File "E:\Program Files (x86)\python\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "E:\Program Files (x86)\python\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:\Program Files (x86)\python\Scripts\pyinstaller.exe\__main__.py", line 9, in
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\__main__.py", line 94, in run
run_build(pyi_config, spec_file, **vars(args))
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "E:\Program Files (x86)\python\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 "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build
exec(text, spec_namespace)
File "
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\building\build_main.py", line 213, in __init__
self.__postinit__()
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
self.assemble()
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\building\build_main.py", line 319, in assemble
excludes=self.excludes, user_hook_dirs=self.hookspath)
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\depend\analysis.py", line 606, in initialize_modgraph
graph.import_hook(m)
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1424, in import_hook
source_package, target_module_partname, level)
File "E:\Program Files (x86)\python\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1602, in _find_head_package
raise ImportError("No module named " + target_package_name)
ImportError: No module named NA1
参考:
https://stackoverflow.com/questions/21657685/python-importerror-cannot-import-name-itemgetter