Using python 3.6 + py2app: why are pyc files generated?

987 views Asked by At

I've written a GUI that I want to turn into a standalone OS X app with py2app. Py2app has succesfully generated a standalone OS X bundle with the following commands:

$ py2applet --make-setup superGui.py
$ python3 setup.py py2app

My setup.py looks like this:

from setuptools import setup

APP = ['/Users/username/PycharmProjects/gui/superGui.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True,
    'plist': {'LSUIElement': True,},
    'includes':['rumps'],}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

I've added the rumps package and LSUIElement based on this documentation. I have the same error with or without them though.

However when I try to run the app with:

$ open dist/superGui.app

I get the following error message in my log:

06/01/17 12:42:51,321 superGui[55597]:   File "<frozen importlib._bootstrap>", line 961, in _find_and_load
06/01/17 12:42:51,322 superGui[55597]:   File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
06/01/17 12:42:51,322 superGui[55597]:   File "<frozen importlib._bootstrap>", line 646, in _load_unlocked
06/01/17 12:42:51,322 superGui[55597]:   File "<frozen importlib._bootstrap>", line 616, in _load_backward_compatible
06/01/17 12:42:51,322 superGui[55597]:   File "scrapy/__init__.pyc", line 10, in <module>
06/01/17 12:42:51,322 superGui[55597]:   File "pkgutil.pyc", line 616, in get_data
06/01/17 12:42:51,322 superGui[55597]:   File "importlib/util.pyc", line 83, in find_spec
06/01/17 12:42:51,322 superGui[55597]: AttributeError: 'NoneType' object has no attribute 'startswith'

I have the following questions:

  1. How do I fix this issue?

  2. The error seems occur when looking in find_spec in "importlib/util.pyc". I don't understand why py2app works with pyc files since I'm using Python 3.6. Python 3.6 doesn't use pyc files any longer right? Does this happen because py2app for some reason uses 2.7 paths? (I also have Python 2.7 installed)

  3. I can't open "importlib/util.pyc" with IDLE 3.6 (again since from what I understand Python 3.6 doesn't support pyc files anymore), but when I open it with IDLE 2.7 I just get a window with a white screen. How can I open this file successfully to understand the error better?

Thanks in advance!

1

There are 1 answers

2
Stephen Rauch On BEST ANSWER

QUESTIONS

  1. How do I fix this issue?

Python packagers are notoriously resistant to answers to this question.

  1. The error seems to occur when looking in find_spec in "importlib/util.pyc".

Don't know much about python 3.6 and freeze tools, but I do know that freeze tools often take a while to catch up to new python packaging/build stuff. Python 3.6 is pretty new. If freezing is important to you now, and you can not get 3.6 going, you might consider python 3.5 or maybe 3.4 for the time being.

  1. How can I open "importlib/util.pyc" successfully to understand the error better?

*.pyc is the compiled version of a .py. It would likely not contain anything you could examine to debug the problem. There should be a importlib/util.py in your python distribution which could be examined.

  1. What else might I try?

A couple of suggestions:

  1. Raise an issue for py2app

  2. Try other freeze tools such as pyinstaller (which does not yet officially support 3.6)