无法让Pyinstaller执行python文件

时间:2017-05-23 14:02:48

标签: python python-3.x pyinstaller

我已经在Python 3.6中编写了一个程序,我尝试使用Pyinstaller来执行它,但后来我发现Pyinstaller只能用于Python 3.5,所以我下载并试图执行该文件它仍然无法正常工作!我发现不同的错误无法找到文件:

100 INFO: PyInstaller: 3.2.1
100 INFO: Python: 3.6.0
100 INFO: Platform: Windows-10-10.0.14393-SP0
100 INFO: wrote C:\Python\pyi-env-name\Scripts\ATM.spec
100 INFO: UPX is not available.
100 INFO: Extending PYTHONPATH with paths
['F:\\', 'C:\\Python\\pyi-env-name\\Scripts']
100 INFO: checking Analysis
100 INFO: Building Analysis because out00-Analysis.toc is non existent
100 INFO: Initializing module dependency graph...
100 INFO: Initializing module graph hooks...
100 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
  File "c:\users\kirsty douglas\appdata\local\programs\python\python36\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\kirsty douglas\appdata\local\programs\python\python36\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python\pyi-env-name\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\building\build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\building\build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\building\build_main.py", line 212, in __init__
    self.__postinit__()
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
    self.assemble()
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\building\build_main.py", line 317, in assemble
    excludes=self.excludes, user_hook_dirs=self.hookspath)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\depend\analysis.py", line 560, in initialize_modgraph
    graph.import_hook(m)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1509, in import_hook
    source_package, target_module_partname, level)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1661, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\depend\analysis.py", line 209, in _safe_import_module
    module_basename, module_name, parent_package)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2077, in _safe_import_module
    module_name, file_handle, pathname, metadata)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2167, in _load_module
    self._scan_code(m, co, co_ast)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2585, in _scan_code
    module, module_code_object, is_scanning_imports=False)
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2831, in _scan_bytecode
    global_attr_name = get_operation_arg_name()
  File "c:\python\pyi-env-name\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2731, in get_operation_arg_name
    return module_code_object.co_names[co_names_index]
IndexError: tuple index out of range

我真的不知道还有什么可以尝试我已经尝试了我能找到的每个教程,甚至我的老师都不知道发生了什么!

编辑::我刚才意识到,在第二行它说

100 INFO: Python: 3.6.0

那么如何才能使用Python 3.5

1 个答案:

答案 0 :(得分:1)

(这应该是评论,但是......代表问题)

您发布的打印输出提到您将其作为Python 3.6运行。为避免这种情况,您可能希望确保PATH变量仅包含所需的安装; 3.5。

这至少可以解决你将它作为错误版本的python运行。它可能无法解决其他问题。

编辑: Windows中的环境变量:

  • 打开文件资源管理器,右键单击左侧窗格中的“此PC”。
  • 单击打开的上下文菜单中的“属性”。
  • 在左侧窗格中,单击“高级系统设置”。
  • 在底部的“高级”标签下,点击环境变量。
  • 在顶部窗格中选择“路径”,然后点击“修改”。
  • 将python的路径更改为所需版本的位置。