包含py2app和boto3编译后,应用在启动时崩溃

时间:2018-10-03 07:00:28

标签: python python-3.x boto3 boto py2app

我创建了一个使用boto3的复杂应用。从命令行运行时,它工作正常。但是,当我尝试使用py2app对其进行编译时,会创建应用程序文件,但在启动时会崩溃。我将其简化为2个文件,发现当包含boto3时它会崩溃,但是当不包含boto3时它可以正常运行。

setup.py

import sys
from setuptools import setup

APP = ['hello.py']
OPTIONS = {'iconfile':'img/icon.icns',}
setup(
    app = APP,
    options = {'py2app': OPTIONS},
    setup_requires = ['py2app'],
)

hello.py

from tkinter import *
import boto3

root = Tk()

w = Label(root, text="Hello, world!")
w.pack()

root.mainloop()

我在MacOS 10.14和10.13上使用最新版本的python 3.7。

我使用命令行:

python3 setup.py py2app

当我编译包含boto3的代码时,我从py2app得到了这些错误。我找不到用pip安装这些模块的方法。

Modules not found (unconditional imports):
 * OpenSSL (botocore.vendored.requests.packages.urllib3.contrib.pyopenssl, urllib3.contrib.pyopenssl)
 * OpenSSL.SSL (urllib3.contrib.pyopenssl)
 * Queue (botocore.vendored.requests.packages.urllib3.connectionpool)
 * Queue.Empty (urllib3.util.queue)
 * Queue.Full (urllib3.util.queue)
 * Queue.LifoQueue (urllib3.util.queue)
 * StringIO.StringIO (botocore.vendored.requests.packages.urllib3.packages.six, botocore.vendored.six, pkg_resources._vendor.six, six, urllib3.packages.six)
 * _abcoll (botocore.vendored.requests.packages.urllib3.packages.ordered_dict, urllib3.packages.ordered_dict)
 * backports.ssl_match_hostname (botocore.vendored.requests.packages.urllib3.packages.ssl_match_hostname, urllib3.packages.ssl_match_hostname)
 * botocore.vendored.six.moves (botocore.httpsession, botocore.vendored.six.moves.urllib.request) [module alias]
 * botocore.vendored.six.moves.http_client (botocore.vendored.six.moves.urllib, botocore.vendored.six.moves.urllib_parse) [module alias]
 * botocore.vendored.six.moves.urllib (botocore.utils) [module alias]
 * botocore.vendored.six.moves.urllib.request (botocore.utils) [module alias]
 * botocore.vendored.six.moves.urllib_parse (botocore.httpsession) [module alias]
 * com (com.sun.jna)
 * com.jna (com.sun)
 * com.sun (com.sun.jna.platform)
 * cryptography (cryptography, cryptography.hazmat.backends, cryptography.x509.extensions, urllib3.contrib.pyopenssl)
 * cryptography.hazmat (cryptography.hazmat.backends.openssl)
 * cryptography.hazmat.backends (cryptography.hazmat.backends.openssl.x509, urllib3.contrib.pyopenssl)
 * cryptography.hazmat.backends.openssl (urllib3.contrib.pyopenssl)
 * cryptography.hazmat.backends.openssl.backend (cryptography.hazmat.backends.openssl.x509)
 * cryptography.hazmat.backends.openssl.x509 (urllib3.contrib.pyopenssl)
 * cryptography.x509 (cryptography.hazmat, cryptography.x509, urllib3.contrib.pyopenssl)
 * cryptography.x509.UnsupportedExtension (cryptography, cryptography.x509.extensions)
 * dummy_thread (botocore.vendored.requests.packages.urllib3.packages.ordered_dict, urllib3.packages.ordered_dict)
 * httplib (botocore.vendored.requests.packages.urllib3.connection, botocore.vendored.requests.packages.urllib3.response)
 * httplib.HTTPConnection (botocore.compat, botocore.vendored.requests.packages.urllib3.response)
 * httplib.HTTPException (botocore.compat, botocore.vendored.requests.packages.urllib3.response)
 * httplib.HTTPResponse (botocore.vendored.requests.packages.urllib3.connection, botocore.vendored.requests.packages.urllib3.response)
 * itertools.izip (collections)
 * itertools.izip_longest (collections)
 * ndg (botocore.vendored.requests.packages.urllib3.contrib.pyopenssl, ndg.httpsclient.subj_alt_name)
 * ndg.SUBJ_ALT_NAME_SUPPORT (ndg.httpsclient)
 * ndg.httpsclient (botocore.vendored.requests.packages.urllib3.contrib.pyopenssl)
 * ndg.httpsclient.subj_alt_name (botocore.vendored.requests.packages.urllib3.contrib.pyopenssl)
 * ordereddict (botocore.compat, pkg_resources._vendor.pyparsing)
 * pyasn1 (botocore.vendored.requests.packages.urllib3.contrib.pyopenssl)
 * pyasn1.decoder (pyasn1.type)
 * pyasn1.type (botocore.vendored.requests.packages.urllib3.contrib.pyopenssl)
 * simplejson (botocore.vendored.requests.compat)
 * six.moves (dateutil.rrule, dateutil.tz.tz, dateutil.tz.win) [module alias]
 * six.moves._thread (dateutil.tz.win) [module alias]
 * six.moves.winreg (dateutil.rrule, dateutil.tz.tz)
 * thread (botocore.vendored.requests.packages.urllib3.packages.ordered_dict, urllib3.packages.ordered_dict)
 * urllib3.packages.six.moves (urllib3.connection, urllib3.connectionpool, urllib3.exceptions, urllib3.packages.six.moves, urllib3.packages.six.moves.urllib.parse, urllib3.response, urllib3.util.queue, urllib3.util.response) [module alias]
 * urllib3.packages.six.moves.http_client (urllib3.connection, urllib3.connectionpool, urllib3.exceptions, urllib3.packages.six.moves.http_client, urllib3.packages.six.moves.urllib, urllib3.util.queue) [module alias]
 * urllib3.packages.six.moves.queue (urllib3.packages.six.moves.http_client, urllib3.packages.six.moves.urllib, urllib3.response, urllib3.util.response) [module alias]
 * urllib3.packages.six.moves.urllib (urllib3.poolmanager, urllib3.request) [module alias]
 * urllib3.packages.six.moves.urllib.parse (urllib3.poolmanager, urllib3.request) [module alias]
 * urlparse (botocore.vendored.requests.packages.urllib3.poolmanager)
 * urlparse.parse_qs (botocore.vendored.requests.compat, botocore.vendored.requests.packages.urllib3.poolmanager)
 * urlparse.parse_qsl (botocore.vendored.requests.compat, botocore.vendored.requests.packages.urllib3.poolmanager)
 * urlparse.urldefrag (botocore.compat, botocore.vendored.requests.packages.urllib3.poolmanager)
 * urlparse.urlparse (botocore.vendored.requests.packages.urllib3.poolmanager)
 * urlparse.urlsplit (botocore.vendored.requests.packages.urllib3.poolmanager)
 * urlparse.urlunparse (botocore.compat, botocore.vendored.requests.packages.urllib3.poolmanager)
 * urlparse.urlunsplit (botocore.vendored.requests.compat, botocore.vendored.requests.packages.urllib3.poolmanager)
 * win32com (win32com)
 * win32com.shell (win32com.shell)
 * win32com.shellcon (win32com.shell)

Modules not found (conditional imports):
 * Cookie (botocore.vendored.requests.compat)
 * OpenSSL.crypto (urllib3.contrib.pyopenssl)
 * Queue (urllib3.util.queue)
 * StringIO (botocore.vendored.requests.compat, botocore.vendored.requests.packages.urllib3.packages.six, botocore.vendored.six, pkg_resources._vendor.six, six, urllib3.packages.six)
 * botocore.vendored.six.moves (botocore.httpsession, botocore.vendored.six.moves.urllib.request) [module alias]
 * com (pkg_resources._vendor.appdirs)
 * com.sun.jna (pkg_resources._vendor.appdirs)
 * com.sun.jna.platform (pkg_resources._vendor.appdirs)
 * cookielib (botocore.vendored.requests.compat)
 * cryptography.x509.extensions (urllib3.contrib.pyopenssl)
 * email.Utils ()
 * httplib (botocore.compat)
 * simplejson (botocore.compat)
 * urllib2 (botocore.vendored.requests.compat)
 * urlparse (botocore.compat, botocore.vendored.requests.compat)
 * win32com (pkg_resources._vendor.appdirs)
 * win32com.shell (pkg_resources._vendor.appdirs)

当我在不使用boto3的情况下进行编译时,会出现以下错误,并且该应用可以正常运行:

Modules not found (unconditional imports):
 * com (com.sun.jna)
 * com.jna (com.sun)
 * com.sun (com.sun.jna.platform)
 * ordereddict (pkg_resources._vendor.pyparsing)
 * win32com (win32com)
 * win32com.shell (win32com.shell)
 * win32com.shellcon (win32com.shell)

Modules not found (conditional imports):
 * StringIO (pkg_resources._vendor.six)
 * com (pkg_resources._vendor.appdirs)
 * com.sun.jna (pkg_resources._vendor.appdirs)
 * com.sun.jna.platform (pkg_resources._vendor.appdirs)
 * win32com (pkg_resources._vendor.appdirs)
 * win32com.shell (pkg_resources._vendor.appdirs)

但是根据py2app的开发者these warnings aren't very important

我着重强调了控制台上两个程序之间唯一的不同,但不是很有帮助: enter image description here

我已经仔细阅读了stackoverflow,但这也是我第一次尝试编译python程序。因此,问题可能是非常独特和不寻常的,或者我犯了一个新错误。

我尝试使用pyinstaller进行类似的操作。它的构建没有错误,但是在执行此错误时被执行崩溃:

distutils.errors.DistutilsModuleError: invalid command 'build'
[42556] Failed to execute script setup

当我尝试使用nuitka时,出现此错误:

Davids-MBP:App degner$ python3 -m nuitka --follow-imports setup.py 
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/__init__.py:11: Cannot find 'setuptools.extern.six' in package 'setuptools' as absolute import (tried setuptools.extern.six).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/__init__.py:12: Cannot find 'setuptools.extern.six.moves' in package 'setuptools' as absolute import (tried setuptools.extern.six.moves).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/command/easy_install.py:46: Cannot find 'setuptools.extern.six.moves' in package 'setuptools.command' as absolute import (tried setuptools.extern.six.moves).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/command/easy_install.py:46: Cannot find 'setuptools.extern.six' in package 'setuptools.command' as absolute import (tried setuptools.extern.six).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/wheel.py:12: Cannot find 'setuptools.extern.packaging.utils' in package 'setuptools' as absolute import (tried setuptools.extern.packaging.utils).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/wheel.py:12: Cannot find 'setuptools.extern.packaging' in package 'setuptools' as absolute import (tried setuptools.extern.packaging).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/pep425tags.py:152: Cannot find '_manylinux' in package 'setuptools' as absolute import (tried _manylinux).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/ssl_support.py:45: Cannot find 'backports.ssl_match_hostname' in package 'setuptools' as absolute import (tried backports.ssl_match_hostname).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/sandbox.py:18: Cannot find 'org.python.modules.posix.PosixModule' in package 'setuptools' as absolute import (tried org.python.modules.posix.PosixModule).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/sandbox.py:18: Cannot find 'org.python.modules.posix' in package 'setuptools' as absolute import (tried org.python.modules.posix).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/sandbox.py:18: Cannot find 'org.python.modules' in package 'setuptools' as absolute import (tried org.python.modules).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/sandbox.py:18: Cannot find 'org.python' in package 'setuptools' as absolute import (tried org.python).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/sandbox.py:18: Cannot find 'org' in package 'setuptools' as absolute import (tried org).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/config.py:10: Cannot find 'setuptools.extern.packaging.version' in package 'setuptools' as absolute import (tried setuptools.extern.packaging.version).
Nuitka:WARNING:/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/setuptools/dist.py:31: Cannot find 'setuptools.extern.packaging.specifiers' in package 'setuptools' as absolute import (tried setuptools.extern.packaging.specifiers).
In file included from setup.build/CompiledCodeHelpers.c:1983:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/static_src/HelpersAttributes.c:553:6: error: conflicting types for 'SET_ATTRIBUTE'
bool SET_ATTRIBUTE(PyObject *target, PyObject *attr_name, PyObject *value) {
     ^
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/include/nuitka/helper/attributes.h:34:13: note: previous declaration is here
extern bool SET_ATTRIBUTE(PyObject *target, PyObject *attr_name, PyObject *value);
            ^
In file included from setup.build/CompiledCodeHelpers.c:1983:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/static_src/HelpersAttributes.c:594:6: error: conflicting types for 'SET_ATTRIBUTE_DICT_SLOT'
bool SET_ATTRIBUTE_DICT_SLOT(PyObject *target, PyObject *value) {
     ^
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/include/nuitka/helper/attributes.h:37:13: note: previous declaration is here
extern bool SET_ATTRIBUTE_DICT_SLOT(PyObject *target, PyObject *value);
            ^
In file included from setup.build/CompiledCodeHelpers.c:1983:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/static_src/HelpersAttributes.c:646:6: error: conflicting types for 'SET_ATTRIBUTE_CLASS_SLOT'
bool SET_ATTRIBUTE_CLASS_SLOT(PyObject *target, PyObject *value) {
     ^
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/nuitka/build/include/nuitka/helper/attributes.h:40:13: note: previous declaration is here
extern bool SET_ATTRIBUTE_CLASS_SLOT(PyObject *target, PyObject *value);
            ^
3 errors generated.
scons: *** [setup.build/CompiledCodeHelpers.o] Error 1

1 个答案:

答案 0 :(得分:0)

py2app中存在一个问题,使其与六个模块不兼容。

现在已修复。

https://bitbucket.org/ronaldoussoren/py2app/issues/250/app-crashes-on-launch-when-compiled-with