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
342 stars 36 forks source link

module zlib has no attribute __file__ #443

Closed ayaland closed 2 years ago

ayaland commented 2 years ago

Running Python 3.6 on Ubuntu 18.04, trying to make an app for husband's Mac. The application does not throw any errors if run in alias mode, but seems to be an issue with zipping.

zlib and zlib-dev for Ubuntu are installed; but there is no [dunderdunder]file[dunderdunder] (sorry, mark-up keeps making the double underscore into bold) in the attributes. Sorry, the code quote eliminates line breaks from the console readout sometimes? Commands run using Python console:

import zlib zlib.[dunderdunder]file[dunderdunder] Traceback (most recent call last): File "/usr/lib/python3.6/code.py", line 91, in runcode exec(code, self.locals) File "<input>", line 1, in <module> AttributeError: module 'zlib' has no attribute '[dunderdunder]file[dunderdunder]' zlib.[dunderdunder]version[dunderdunder] '1.0' print(dir(zlib)) ['DEFLATED', 'DEF_BUF_SIZE', 'DEF_MEM_LEVEL', 'MAX_WBITS', 'ZLIB_RUNTIME_VERSION', 'ZLIB_VERSION', 'Z_BEST_COMPRESSION', 'Z_BEST_SPEED', 'Z_BLOCK', 'Z_DEFAULT_COMPRESSION', 'Z_DEFAULT_STRATEGY', 'Z_FILTERED', 'Z_FINISH', 'Z_FIXED', 'Z_FULL_FLUSH', 'Z_HUFFMAN_ONLY', 'Z_NO_COMPRESSION', 'Z_NO_FLUSH', 'Z_PARTIAL_FLUSH', 'Z_RLE', 'Z_SYNC_FLUSH', 'Z_TREES', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '__version__', 'adler32', 'compress', 'compressobj', 'crc32', 'decompress', 'decompressobj', 'error']

Here is the terminal output when trying to run setup.py without alias mode: *** creating application bundle: scoreWidget *** Copy '/home/aya/.local/lib/python3.6/site-packages/py2app/apptemplate/prebuilt/main-x86_64-oldsdk' -> '/home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/MacOS/scoreWidget' byte-compiling /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/site.py to site.pyc copying file scoreWidget.py -> /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources creating /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib creating /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib/python3.6 creating /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib/python3.6/config-3.6m-x86_64-linux-gnu copying file /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/Makefile -> /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib/python3.6/config-3.6m-x86_64-linux-gnu/Makefile copying file /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/Setup -> /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib/python3.6/config-3.6m-x86_64-linux-gnu/Setup copying file /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/Setup.local -> /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib/python3.6/config-3.6m-x86_64-linux-gnu/Setup.local copying file /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/Setup.config -> /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib/python3.6/config-3.6m-x86_64-linux-gnu/Setup.config creating /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/include creating /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/include/python3.6m copying file /usr/include/python3.6m/pyconfig.h -> /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/include/python3.6m/pyconfig.h copying file build/bdist.linux-x86_64/python3.6-standalone/app/python36.zip -> /home/aya/PycharmProjects/score_widget/dist/scoreWidget.app/Contents/Resources/lib Traceback (most recent call last): File "setup.py", line 18, in <module> setup_requires=['py2app'], File "/home/aya/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup return distutils.core.setup(**attrs) File "/usr/lib/python3.6/distutils/core.py", line 148, in setup dist.run_commands() File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/home/aya/.local/lib/python3.6/site-packages/py2app/build_app.py", line 964, in run self._run() File "/home/aya/.local/lib/python3.6/site-packages/py2app/build_app.py", line 1194, in _run self.run_normal() File "/home/aya/.local/lib/python3.6/site-packages/py2app/build_app.py", line 1307, in run_normal self.create_binaries(py_files, pkgdirs, extensions, loader_files) File "/home/aya/.local/lib/python3.6/site-packages/py2app/build_app.py", line 1665, in create_binaries target, arcname, pkgexts, copyexts, target.script, extra_scripts File "/home/aya/.local/lib/python3.6/site-packages/py2app/build_app.py", line 2477, in build_executable self.copy_file(zlib.__file__, os.path.dirname(arcdir)) AttributeError: module 'zlib' has no attribute '__file__'

ronaldoussoren commented 2 years ago

Py2app must be run on macOS, it cannot be used to cross-build applications on Linux or Windows. I've updated the py2app documentation to be more clear about this.

The reason for this is that applications contain both Python code and C code (if only for Python itself and the stdlib). During the construction of the application py2app needs to access and load that C code. That only works when running on a macOS system.