+
Skip to content

build_app attempts to copy zlib and it doesn't need to with Python3.11 #555

@sheffler

Description

@sheffler

When running py2app on Mac with a Python3.11 installed in a venv by 'uv', my build fails with the following

  File "/Users/sheffler/git/kivy_osx/.venv/lib/python3.11/site-packages/py2app/build_app.py", line 1217, in _run
    self.run_normal()
  File "/Users/sheffler/git/kivy_osx/.venv/lib/python3.11/site-packages/py2app/build_app.py", line 1330, in run_normal
    self.create_binaries(py_files, pkgdirs, extensions, loader_files)
  File "/Users/sheffler/git/kivy_osx/.venv/lib/python3.11/site-packages/py2app/build_app.py", line 1687, in create_binaries
    dst = self.build_executable(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sheffler/git/kivy_osx/.venv/lib/python3.11/site-packages/py2app/build_app.py", line 2508, in build_executable
    self.copy_file(zlib.__file__, os.path.dirname(arcdir))
                   ^^^^^^^^^^^^^
AttributeError: module 'zlib' has no attribute '__file__'. Did you mean: '__name__'?

In build_app.py there are these lines:

        if sys.version_info[0] != 2:
            import zlib

            self.copy_file(zlib.__file__, os.path.dirname(arcdir))

If I copy out the block of code above, the build works fine and the executable runs as well. The reason seems to be that the version of python I am using in the .venv is Python3.11 and 'zlib' seems to be a built in

$ python
Python 3.11.11 (main, Dec  6 2024, 21:09:50) [Clang 18.1.8 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
>>> 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', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '__version__', 'adler32', 'compress', 'compressobj', 'crc32', 'decompress', 'decompressobj', 'error']
>>> zlib.__loader__
<class '_frozen_importlib.BuiltinImporter'>
>>> 

IN the system's python3.10, it is loaded from a file

$ /usr/bin/python3
Python 3.9.6 (default, Apr 30 2025, 02:07:17) 
[Clang 17.0.0 (clang-1700.0.13.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
>>> zlib.__file__
'/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload/zlib.cpython-39-darwin.so'
>>> 

Not sure how to handle this, perhaps it is related to the python that uv installed.
Reporting it here regardless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载