Skip to content

setup.py should not set zip_safe to True #5356

@AkarinVS

Description

@AkarinVS

What did you do?

on vanilla macOS with xcode and necessary prerequisites installed (as static libraries), run

python3 setup.py install && python3 -c "from PIL import Image"

What did you expect to happen?

The import should be successful.

What actually happened?

Core version: None
Pillow version: 8.1.2
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen zipimport>", line 259, in load_module
  File "...../lib/python3.8/site-packages/Pillow-8.1.2-py3.8-macosx-10.15-x86_64.egg/PIL/Image.py", line 97, in <module>
ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: None
Pillow version: 8.1.2

The real cause is not because the _imaging.so native module is compiled for another version (as we just built it), but because Python is unable to dlopen it at all.

What are your OS, Python and Pillow versions?

  • OS: macOS 10.15
  • Python: 3.8.8
  • Pillow: 8.1.2

Suspected Cause

We specified zip_safe to be generally True unless it's a debugging build or mingw build.

Pillow/setup.py

Line 912 in 51bbefe

zip_safe=not (debug_build() or PLATFORM_MINGW),

However, Python is unable to import a dynamic library from a zip file. Therefore, this package should definitely not be labeled zip_safe. I have checked many installations, and on many,easy_install somehow knows to extract the content of the egg into its a directory, thus hiding this issue on lots of platforms. I'm not yet sure why this doesn't happen on macOS. But nevertheless, I don't think we should use zip_safe: True on any platform: as https://docs.python.org/3/library/zipimport.html explicitly disallows importing dynamic modules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    InstallationUsually a problem with …

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions