用Pyinstaller打包时报错

我使用的python是 3.6.1 , PyInstaller用的是 3.2.1
用pyinstaller打包就出现以下情况:

C:\package>pyinstaller -F game.py
166 INFO: PyInstaller: 3.2.1
166 INFO: Python: 3.6.1
166 INFO: Platform: Windows-10-10.0.14393-SP0
166 INFO: wrote C:\package\game.spec
182 INFO: UPX is not available.
182 INFO: Extending PYTHONPATH with paths
['C:\\package', 'C:\\package']
182 INFO: checking Analysis
182 INFO: Building Analysis because out00-Analysis.toc is non existent
182 INFO: Initializing module dependency graph...
199 INFO: Initializing module graph hooks...
202 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
  File "C:\Python36\Scripts\pyinstaller-script.py", line 11, in <module>
    load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\building\build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\building\build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\building\build_main.py", line 212, in __init__
    self.__postinit__()
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\building\datastruct.py", line 161, in __postinit__
    self.assemble()
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\building\build_main.py", line 317, in assemble
    excludes=self.excludes, user_hook_dirs=self.hookspath)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\depend\analysis.py", line 560, in initialize_modgraph
    graph.import_hook(m)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 1509, in import_hook
    source_package, target_module_partname, level)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 1661, in _find_head_p
ackage
    target_module_headname, target_package_name, source_package)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\depend\analysis.py", line 209, in _safe_import_module
    module_basename, module_name, parent_package)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 2077, in _safe_import
_module
    module_name, file_handle, pathname, metadata)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 2167, in _load_module

    self._scan_code(m, co, co_ast)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 2585, in _scan_code
    module, module_code_object, is_scanning_imports=False)
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 2831, in _scan_byteco
de
    global_attr_name = get_operation_arg_name()
  File "C:\Python36\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 2731, in get_operatio
n_arg_name
    return module_code_object.co_names[co_names_index]
IndexError: tuple index out of range

经过各种查数据发现其实是pyinstaller3.2.1不支持Python 3.6
因此解决办法有两个:
1.python不要用3.6的,改用3.5的
2.删掉python/Lib/site-packages/PyInstaller 文件夹,然后点击下载PyInstaller,解压并把PyInstaller文件夹放到python/Lib/site-packages/目录下面就OK了

以下是pyinstaller的一些参数说明:

-F 表示生成单个可执行文件
-w 表示去掉控制台窗口,这在GUI界面时非常有用。不过如果是命令行程序的话那就把这个选项删除吧!
-p 表示你自己自定义需要加载的类路径,一般情况下用不到
-i 表示可执行文件的图标

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值