为Python 3.6 windows 10x64转换.py到.exe的最佳方法?

时间:2017-08-01 19:34:55

标签: python pyinstaller py2exe cx-freeze index-error

我尝试使用像py2exe,cx_Freeze,pyinstaller这样的东西,但到目前为止没有任何效果可能是因为它们都支持旧版本。我正在寻找一个支持新版本或一些简单的步骤来至少让这些工作。 任何帮助将受到高度赞赏。  我在最后一步中遇到了各自的错误: -

setup.py

from distutils.core import setup
import py2exe

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

py2exe 创建安装文件后

C:\WINDOWS\system32>cd C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32

C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32>python setup.py py2exe
running py2exe
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(console=['pricecomparisontool.py'])
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
    self._run()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
    builder.analyze()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\runtime.py", line 160, in analyze
    self.mf.import_hook(modname)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
    module = self._gcd_import(name)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
    return self._find_and_load(name)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
    self._scan_code(module.__code__, module)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
    for what, args in self._scan_opcodes(code):
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
    yield "store", (names[oparg],)
IndexError: tuple index out of range

setup.py

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "pricecomparisontool",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("pricecomparisontool.py", base=base)])

cx_Freeze 在创建设置文件时

C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32>python setup.py build
running build
running build_exe
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    executables = [Executable("pricecomparisontool.py", base=base)])
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
    distutils.core.setup(**attrs)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\command\build.py", line 135, in run
    self.run_command(cmd_name)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 218, in run
    zipExcludePackages = self.zip_exclude_packages)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 149, in __init__
    self._VerifyConfiguration()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 483, in _VerifyConfiguration
    executable._VerifyConfiguration(self)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 686, in _VerifyConfiguration
    self._GetInitScriptFileName()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 708, in _GetInitScriptFileName
    raise ConfigError("no initscript named %s", name)
cx_Freeze.freezer.ConfigError: no initscript named Console

setup.py

#! /usr/bin/env python
#-----------------------------------------------------------------------------
# Copyright (c) 2005-2016, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

from __future__ import print_function

import codecs
import sys, os
from setuptools import setup
from PyInstaller import (__version__ as version, is_linux, is_win, is_cygwin,
                         HOMEPATH, PLATFORM, compat)


REQUIREMENTS = ['setuptools']
# For Windows install PyWin32 if not already installed.
if sys.platform.startswith('win'):
    # Windows support depends on pefile library.
    # ::TODO:: #1920 require a specific version minimum
    # REQUIREMENTS.append('pefile')
    # ::TODO:: #1920 future is currently only needed for the included pefile,
    # remove 'future' as requirement when pypi pefile is used
    REQUIREMENTS.append('future')
    try:
        import pywintypes
    except ImportError:
        # 'pypiwin32' is PyWin32 package made installable by 'pip install'
        # command.
        REQUIREMENTS.append('pypiwin32')


# Create long description from README.rst and doc/CHANGES.rst.
# PYPI page will contain complete PyInstaller changelog.
def read(filename):
    try:
        return unicode(codecs.open(filename, encoding='utf-8').read())
    except NameError:
        return open(filename, 'r', encoding='utf-8').read()
long_description = u'\n\n'.join([read('README.rst'),
                                 read('doc/CHANGES.rst')])
if sys.version_info < (3,):
    long_description = long_description.encode('utf-8')


CLASSIFIERS = """
Development Status :: 6 - Mature
Environment :: Console
Intended Audience :: Developers
Intended Audience :: Other Audience
Intended Audience :: System Administrators
License :: OSI Approved :: GNU General Public License v2 (GPLv2)
Natural Language :: English
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: POSIX :: AIX
Operating System :: POSIX :: BSD
Operating System :: POSIX :: Linux
Operating System :: POSIX :: SunOS/Solaris
Programming Language :: C
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: Implementation :: CPython
Topic :: Software Development
Topic :: Software Development :: Build Tools
Topic :: Software Development :: Interpreters
Topic :: Software Development :: Libraries :: Python Modules
Topic :: System :: Installation/Setup
Topic :: System :: Software Distribution
Topic :: Utilities
""".strip().splitlines()


#-- plug-in building the bootloader

from distutils.core import Command
from distutils.command.build import build
from setuptools.command.bdist_egg import bdist_egg


class build_bootloader(Command):
    """
    Wrapper for distutil command `build`.
    """

    user_options =[]
    def initialize_options(self): pass
    def finalize_options(self): pass

    def bootloader_exists(self):
        # Checks is the console, non-debug bootloader exists
        exe = 'run'
        if is_win or is_cygwin:
            exe = 'run.exe'
        exe = os.path.join(HOMEPATH, 'PyInstaller', 'bootloader', PLATFORM, exe)
        return os.path.isfile(exe)

    def compile_bootloader(self):
        import subprocess

        src_dir = os.path.join(HOMEPATH, 'bootloader')
        cmd = [sys.executable, './waf', 'configure', 'all']
        if is_linux:
            env = os.environ.copy()
            try:
                env['PATH'] += ':/opt/lsb/bin'
            except:
                env['PATH'] = '/opt/lsb/bin'
            lsb = False
            try:
                FNULL = open(os.devnull, 'w')
                if subprocess.call(['which', 'lsbcc'], env=env,
                                   stderr=FNULL, stdout=FNULL,
                                   close_fds=True) == 0:
                    lsb = True
            except compat.FileNotFoundError:
                pass
            if not lsb:
                cmd.append('--no-lsb')
        rc = subprocess.call(cmd, cwd=src_dir)
        if rc:
            raise SystemExit('ERROR: Failed compiling the bootloader. '
                             'Please compile manually and rerun setup.py')

    def run(self):
        if getattr(self, 'dry_run', False):
            return
        if self.bootloader_exists():
            return
        print('No precompiled bootloader found. Trying to compile it for you ...',
              file=sys.stderr)
        self.compile_bootloader()


class MyBuild(build):
    # plug `build_bootloader` into the `build` command
    def run(self):
        self.run_command('build_bootloader')
        build.run(self)

class MyBDist_Egg(bdist_egg):
    def run(self):
        self.run_command('build_bootloader')
        bdist_egg.run(self)

#--

setup(
    install_requires=REQUIREMENTS,

    name='PyInstaller',
    version=version,

    description='PyInstaller bundles a Python application and all its '
                'dependencies into a single package.',
    long_description=long_description,
    keywords='packaging app apps bundle convert standalone executable '
             'pyinstaller macholib cxfreeze freeze py2exe py2app bbfreeze',

    author='Giovanni Bajo, Hartmut Goebel, David Vierra, David Cortesi, Martin Zibricky',
    author_email='pyinstaller@googlegroups.com',

    license=('GPL license with a special exception which allows to use '
             'PyInstaller to build and distribute non-free programs '
             '(including commercial ones)'),
    url='http://www.pyinstaller.org',

    cmdclass = {'build_bootloader': build_bootloader,
                'build': MyBuild,
                'bdist_egg': MyBDist_Egg,
                },

    classifiers=CLASSIFIERS,
    zip_safe=False,
    packages=['PyInstaller'],
    package_data={
        # This includes precompiled bootloaders and icons for bootloaders.
        'PyInstaller': ['bootloader/*/*'],
        # This file is necessary for rthooks (runtime hooks).
        'PyInstaller.loader': ['rthooks.dat'],
        },
    include_package_data=True,

    entry_points={
        'console_scripts': [
            'pyinstaller = PyInstaller.__main__:run',
            'pyi-archive_viewer = PyInstaller.utils.cliutils.archive_viewer:run',
            'pyi-bindepend = PyInstaller.utils.cliutils.bindepend:run',
            'pyi-grab_version = PyInstaller.utils.cliutils.grab_version:run',
            'pyi-makespec = PyInstaller.utils.cliutils.makespec:run',
            'pyi-set_version = PyInstaller.utils.cliutils.set_version:run',
        ],
    }
)

pyinstaller 几乎与py2exe类似的错误我想

C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32>cd C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1

C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1>python pyinstaller.py --onefile pricecomparisontool.py
3627 INFO: PyInstaller: 3.2.1
3641 INFO: Python: 3.6.1
3642 INFO: Platform: Windows-10-10.0.15063-SP0
3644 INFO: wrote C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\pricecomparisontool\pricecomparisontool.spec
3645 INFO: UPX is not available.
Traceback (most recent call last):
  File "pyinstaller.py", line 15, in <module>
    run()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\build_main.py", line 162, in __init__
    raise ValueError("script '%s' not found" % script)
ValueError: script 'C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\pricecomparisontool.py' not found

C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1>python pyinstaller.py --onefile pricecomparisontool.py
378 INFO: PyInstaller: 3.2.1
378 INFO: Python: 3.6.1
380 INFO: Platform: Windows-10-10.0.15063-SP0
382 INFO: wrote C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\pricecomparisontool\pricecomparisontool.spec
384 INFO: UPX is not available.
402 INFO: Extending PYTHONPATH with paths
['C:\\Users\\WINLAP307\\AppData\\Local\\Programs\\Python\\Python36-32\\PyInstaller-3.2.1',
 'C:\\Users\\WINLAP307\\AppData\\Local\\Programs\\Python\\Python36-32\\PyInstaller-3.2.1\\pricecomparisontool']
407 INFO: checking Analysis
408 INFO: Building Analysis because out00-Analysis.toc is non existent
408 INFO: Initializing module dependency graph...
423 INFO: Initializing module graph hooks...
494 INFO: Analyzing base_library.zip ...
Traceback (most recent call last):
  File "pyinstaller.py", line 15, in <module>
    run()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\__main__.py", line 90, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\build_main.py", line 788, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\build_main.py", line 734, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\build_main.py", line 212, in __init__
    self.__postinit__()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\datastruct.py", line 161, in __postinit__
    self.assemble()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\building\build_main.py", line 317, in assemble
    excludes=self.excludes, user_hook_dirs=self.hookspath)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\depend\analysis.py", line 560, in initialize_modgraph
    graph.import_hook(m)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\lib\modulegraph\modulegraph.py", line 1509, in import_hook
    source_package, target_module_partname, level)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\lib\modulegraph\modulegraph.py", line 1661, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\depend\analysis.py", line 209, in _safe_import_module
    module_basename, module_name, parent_package)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\lib\modulegraph\modulegraph.py", line 2077, in _safe_import_module
    module_name, file_handle, pathname, metadata)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\lib\modulegraph\modulegraph.py", line 2167, in _load_module
    self._scan_code(m, co, co_ast)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\lib\modulegraph\modulegraph.py", line 2585, in _scan_code
    module, module_code_object, is_scanning_imports=False)
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\PyInstaller\lib\modulegraph\modulegraph.py", line 2831, in _scan_bytecode
    global_attr_name = get_operation_arg_name()
  File "C:\Users\WINLAP307\AppData\Local\Programs\Python\Python36-32\PyInstaller-3.2.1\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

我无法调试这些,也请随时询问是否有任何进一步的细节...

0 个答案:

没有答案