Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: AttributeError: module 'PIL' has no attribute 'PngImagePlugin' #292

Closed
CarloLucibello opened this issue Apr 12, 2023 · 2 comments
Closed

Comments

@CarloLucibello
Copy link
Contributor

Hi,
I have a problem with my package where I import the pillow module as the PIL variable in the package's init
https://github.com/CarloLucibello/HuggingFaceDatasets.jl/blob/3362f5650483e6ace17e7f2d98af36252d9f4316/src/HuggingFaceDatasets.jl#L43

I run the package's tests

include("test/runtests.jl")

and I get the error

Python: AttributeError: module 'PIL' has no attribute 'PngImagePlugin'
  Python stacktrace: none
  Stacktrace:
    [1] pythrow()
      @ PythonCall ~/.julia/packages/PythonCall/dsECZ/src/err.jl:94
    [2] errcheck
      @ ~/.julia/packages/PythonCall/dsECZ/src/err.jl:10 [inlined]
    [3] pygetattr(x::Py, k::String)
      @ PythonCall ~/.julia/packages/PythonCall/dsECZ/src/abstract/object.jl:60
    [4] getproperty
      @ ~/.julia/packages/PythonCall/dsECZ/src/Py.jl:272 [inlined]
    [5] _pyconvert(x::Py)
      @ HuggingFaceDatasets ~/juliadev/HuggingFaceDatasets/src/transforms.jl:8
    [6] py2jl(x::Py)
      @ HuggingFaceDatasets ~/juliadev/HuggingFaceDatasets/src/transforms.jl:33

The weird thing is that the module actually exists

julia> HuggingFaceDatasets.PIL.PngImagePlugin
Python module: <module 'PIL.PngImagePlugin' from '/home/lucibello/juliadev/HuggingFaceDatasets/.CondaPkg/env/lib/python3.11/site-packages/PIL/PngImagePlugin.py'>

and that when I rum some of the tests individually the error disappears and after that also include("test/runtests.jl") works fine.
Any clue?

@cjdoris
Copy link
Collaborator

cjdoris commented Apr 24, 2023

Presumably the code is trying to access PIL.PngImagePlugin before it has been imported. This sounds like a bug in your tests.

It probably works after running some other tests because they probably do import that module, so it is available again later through attribute access.

@CarloLucibello
Copy link
Contributor Author

CarloLucibello commented May 23, 2023

having

PythonCall.pycopy!(PIL, pyimport("PIL"))
pyimport("PIL.PngImagePlugin")

in the package __init__ solves the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants