2017-08-07 20 views
2

私のpythonスクリプトを.exeファイルに変換しようとしています。pythonスクリプトエラーのための.exeの作成

私はpy2exeライブラリを使用して、私のpythonスクリプトの変換を試みました。

Pythonスクリプトが一行だけ持っています:pythonセットアップ:

print ("hello world") 

と私のスクリプトが

from distutils.core import setup 
import py2exe 

setup (console=['py2exetut.py']) 

をexeファイルに変換してます別のスクリプトを私はコマンドを使用して、このスクリプトを実行するとき。

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 
:PY py2exe

私はこのエラーを取得しています

そして私は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 

注:私はWindows 7 OSとPython 3.6を使用しています。

だから、この問題はパッケージにないと思います。どのような方法を進める?

答えて

2

py2exeは3.6にはお勧めできません(通常はPython 2.xを使用します)。そのためにはcx_Freezeライブラリを使用してください。

hereからダウンロードできます。

また、cmdプロンプトpip install cx_Freezeを入力することもできます。

通常のsetup.pyスクリプト:スクリプトがより複雑になるにつれ

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) 

、あなたはsetup()機能上の複数の項目を含める必要がありますが、executables変数が最も重要な部分です。

+0

cx_Freezeチャームのように動作します。ありがとうございました! –

関連する問題