ronaldoussoren / py2app

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.
Other
343 stars 36 forks source link

py2app 0.26 error #378

Open hasii2011 opened 2 years ago

hasii2011 commented 2 years ago

On python 3.9.0 with mypy 0.910 installed I can successfully build my app gittodoist

However, when I upgrade to python 3.9.1 with all my dependencies the same including py2app and mypy I get the following error:

File "/Users/humberto.a.sanchez.ii/PycharmProjects/gittodoistclone/pyenv-venv-3.9.1/lib/python3.9/site-packages/py2app/util.py", line 497, in byte_compile raise RuntimeError("Don't know how to handle %r" % mod.filename) RuntimeError: Don't know how to handle '/Users/humberto.a.sanchez.ii/PycharmProjects/gittodoistclone/pyenv-venv-3.9.1/lib/python3.9/site-packages/mypy/__init__'

If I uninstall mypy on the 3.9.1 environment, I can successfully build again.

I use pyenv to switch python versions; And use venv to create virtual build environments for the above;

As a workaround, I uninstall mypy on 3.9.1

MAKOMO commented 2 years ago

Hm. I encounter similar troubles. With mypy installed I cannot build my app with py2app. I have to uninstall it.

ronaldoussoren commented 2 years ago

I'm working on this, and expect that this has to do with having both python files and C extensions of the same base name. If that's the issue the workaround is to install the platform independent wheel for Mypy (although that will be slower).

ronaldoussoren commented 2 years ago

I need some more information to reproduce the issue...

I've tried to reproduce the issue with examples/simple and:

Traceback (most recent call last):
  ...
  File ".../py2app/examples/simple/dist/hello.app/Contents/Resources/hello.py", line 3, in <module>
    import mypy
ModuleNotFoundError: No module named 'a64f60bb4641b67cb20c__mypyc'

This is likely due to an import in the C extensions included with Mypy. Running the app (with just the import statement) works just fine when I install the platform independent wheel. The issue I ran into above can be fixed with a recipe, but is not the issue you are reporting :-(

MAKOMO commented 2 years ago

Ronald,

the funny thing is that mypy is NOT used (imported) by the app. However, the apps code contains some Python3 static type annotations (which is the whole point of using mypy to check them).

I am not using a virtual environment. All packages are installed directly using sudo pip on my mac running Python 3.9.7.

With mypy installed I get

writing byte-compilation script '/tmp/tmpovsp5f9d.py'
/usr/bin/env PYTHONPATH=/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/py2app-0.26.1-py3.9.egg:/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9 /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -OO /tmp/tmpovsp5f9d.py
Traceback (most recent call last):
  File "/tmp/tmpovsp5f9d.py", line 1222, in <module>
    byte_compile(files, optimize=2, force=None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/py2app-0.26.1-py3.9.egg/py2app/util.py", line 497, in byte_compile
    raise RuntimeError("Don't know how to handle %r" % mod.filename)
RuntimeError: Don't know how to handle '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mypy/__init__'
error: command '/usr/bin/env' failed with exit code 1

Sadly the project is large and one needs to install quite some packages (specified in requirements*.txt) and then run

# sudo ./build-mac3.sh

to start the build. The project is on GitHub: https://github.com/artisan-roaster-scope/artisan

If I can add some debug statements somewhere or help otherwise, let me know.

Marko

PS: Here is that file /tmp/tmpovsp5f9d.py

tmpovsp5f9d.py.txt

hasii2011 commented 2 years ago

When you say import from a platform independent wheel is that PyPi? To answer your questions

Yes, you can git clone the gittodoistclone project

pip3 install -r requirements.txt

then run

./scripts/packageme.sh deploy

That should show the problem

hasii2011 commented 2 years ago

Ok, upgrade to 0.26.1 and problem goes away. Reverted back to 0.26 and problem does not exist anymore; Not sure what happened; But I am going to stay on 0.26.1

I am ok with closing this assuming @MAKOMO is ok also

MAKOMO commented 2 years ago

Hm. I checked if the order of pip installs resolves this (pip install mypy before or after py2app). No change for me. However, my error message is slightly different from yours:

*** filtering dependencies ***
6221 total
47 filtered
183 orphaned
6174 remaining
*** create binaries ***
*** byte compile python files ***
writing byte-compilation script '/tmp/tmpwq8cwvba.py'
/usr/bin/env PYTHONPATH=/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages:/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9 /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -OO /tmp/tmpwq8cwvba.py
Traceback (most recent call last):
  File "/tmp/tmpwq8cwvba.py", line 1209, in <module>
    byte_compile(files, optimize=2, force=None,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/py2app/util.py", line 497, in byte_compile
    raise RuntimeError("Don't know how to handle %r" % mod.filename)
RuntimeError: Don't know how to handle '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mypy/__init__'
error: command '/usr/bin/env' failed with exit code 1

I wonder what mypy has to do with py2app at all. Very strange.