为python脚本创建.exe时出错

为python脚本创建.exe时出错,python,py2exe,Python,Py2exe,我正在尝试将python脚本转换为.exe文件 最初,我尝试使用py2exe库为我的python脚本执行此转换 python脚本只有一行: print ("hello world") 和另一个将我的脚本转换为.exe的脚本 from distutils.core import setup import py2exe setup (console=['py2exetut.py']) 当我使用命令python setup.py py2exe运行这个脚本时 我得到这个错误: runnin

我正在尝试将python脚本转换为.exe文件

最初,我尝试使用py2exe库为我的python脚本执行此转换

python脚本只有一行:

print ("hello world")
和另一个将我的脚本转换为.exe的脚本

from distutils.core import setup
import py2exe

setup (console=['py2exetut.py'])
当我使用命令python setup.py py2exe运行这个脚本时

我得到这个错误:

    running py2exe
    Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup (console=['py2exetut.py'])
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
    self._run()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
    builder.analyze()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\runtime.py", line 159, in analyze
    self.mf.import_hook(modname)
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
    module = self._gcd_import(name)
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
    return self._find_and_load(name)
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 352, in _scan_code
    for what, args in self._scan_opcodes(code):
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 381, in _scan_opcodes
    yield "store", (names[oparg],)
IndexError: tuple index out of range
运行py2exe
回溯(最近一次呼叫最后一次):
文件“setup.py”,第4行,在
安装程序(控制台=['py2exetut.py'])
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py”,第148行,在安装程序中
dist.run_命令()
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py”,第955行,在run\u命令中
self.run_命令(cmd)
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py”,第974行,在run\u命令中
cmd_obj.run()
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\distutils\u buildexe.py”,第188行,正在运行
self._run()
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\distutils\u buildexe.py”,第267行,正在运行
builder.analyze()
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\runtime.py”,第159行,在analyze中
self.mf.import_hook(modname)
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\mf3.py”,第117行,在导入钩子中
模块=self.\u gcd\u导入(名称)
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\mf3.py”,第267行,在\u gcd\u import中
返回自我。查找并加载(名称)
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\mf3.py”,第320行,在查找和加载中
自我扫描代码(模块代码,模块)
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\mf3.py”,第352行,在扫描代码中
对于什么,在self.\u scan\u操作码(代码)中的参数:
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\py2exe\mf3.py”,第381行,在扫描操作码中
收益率“存储”(名称[oparg],)
索引器错误:元组索引超出范围
然后我尝试使用Pyinstaller另一个包,使用类似的过程,我得到类似的错误,如下所示:

  pyinstaller file-creator.py
126 INFO: PyInstaller: 3.2.1
126 INFO: Python: 3.6.1
127 INFO: Platform: Windows-7-6.1.7601-SP1
128 INFO: wrote C:\Deepan\exe python\file-creator.spec
136 INFO: UPX is not available.
143 INFO: Extending PYTHONPATH with paths
['C:\\Deepan\\exe python', 'C:\\Deepan\\exe python']
144 INFO: checking Analysis
145 INFO: Building Analysis because out00-Analysis.toc is non existent
145 INFO: Initializing module dependency graph...
149 INFO: Initializing module graph hooks...
153 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\Scripts\pyinstaller-script.py", line 11, in <module>
    load_entry_point('PyInstaller==3.2.1', 'console_scripts', 'pyinstaller')()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\building\build_main.py", line 212, in __init__
    self.__postinit__()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\building\datastruct.py", line 161, in __postinit__
    self.assemble()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 1661, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\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:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\PyInstaller\lib\modulegraph\modulegraph.py", line 2831, in _scan_bytecode
    global_attr_name = get_operation_arg_name()
  File "C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyinstaller-3.2.1-py3.6.egg\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
pyinstaller file-creator.py
126信息:PyInstaller:3.2.1
126信息:Python:3.6.1
127信息:平台:Windows-7-6.1.7601-SP1
128信息:编写了C:\Deepan\exe python\file-creator.spec
136信息:UPX不可用。
143信息:使用路径扩展PYTHONPATH
['C:\\Deepan\\exe python','C:\\Deepan\\exe python']
144信息:检查分析
145信息:正在生成分析,因为out00-Analysis.toc不存在
145信息:正在初始化模块依赖关系图。。。
149信息:正在初始化模块图挂钩。。。
153信息:正在分析base_library.zip。。。
回溯(最近一次呼叫最后一次):
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\Scripts\pyinstaller script.py”,第11行,在
加载入口点('PyInstaller==3.2.1','console\u scripts','PyInstaller')()
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\\ uuuuuu main\uuuuuu.py”,第90行,正在运行
运行构建(pyi\u配置,规范文件,**vars(args))
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\\ uuuuuuuuuuuuuuuuuuuuuuuuuuuu.py”,第46行,在运行版本中
PyInstaller.building.build\u main.main(pyi\u配置,spec\u文件,**kwargs)
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\building\building\u main.py”,第788行,主目录
构建(specfile,kw.get('distpath'),kw.get('workpath'),kw.get('clean_build'))
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\building\building\u main.py”,第734行,内部版本
exec(文本,规范名称空间)
文件“”,第16行,在
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\building\building\build\u main.py”,第212行,在u init中__
self.\uuuu postinit\uuuuu()
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\building\datastruct.py”,第161行,位于__
self.assembly()
汇编中第317行的文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\building\build\u main.py”
excludes=self.excludes,user\u hook\u dirs=self.hookspath)
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\dependent\analysis.py”,第560行,在initialize\u modgraph中
图.导入钩(m)
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\lib\modulegraph\modulegraph.py”,第1509行,导入
源\包、目标\模块\部件名、级别)
文件“C:\Users\draj3\AppData\Local\Programs\Python\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\lib\modulegraph\modulegraph.py”,第1661行,位于\u find\u head\u package中
目标\模块\头名、目标\包\名、源\包)
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\dependent\analysis.py”,第209行,位于安全导入模块中
模块\基本名称、模块\名称、父\包)
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\lib\modulegraph\modulegraph.py”,第2077行,在“安全导入”模块中
模块名称、文件句柄、路径名、元数据)
文件“C:\Users\draj3\AppData\Local\Programs\Python36-32\lib\site packages\pyinstaller-3.2.1-py3.6.egg\pyinstaller\lib\module”
import cx_Freeze as cx_f #for now, do the wildcard import, though the bigger the script gets, I would recommend an as ... structure

executables = [cx_f.Executable("Oilfield.py")]

cx_f.setup(name="whatever you want", executables=executables)