Skip to content

Python package works on Julia 1.11 and 1.13 but errors on 1.12 #735

Description

@nhz2

Affects: PythonCall

Describe the bug
I expect the following output when using imagecodecs:

using Pkg
Pkg.activate(;temp=true)
pkg"add PythonCall CondaPkg"
using CondaPkg
pkg"conda pip_add imagecodecs"
using PythonCall
imcd = pyimport("imagecodecs")
imcd.lzma_encode(UInt8[])
# Python: b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x00\x00\x00\x00\x1c\xdfD!\x1f\xb6\xf3}\x01\x00\x00\x00\x00\x04YZ'

This works on Julia 1.11.8 and Julia 1.13.0-alpha2, but on Julia 1.12.3 I get:

julia> imcd.lzma_encode(UInt8[])
ERROR: Python: LzmaError: lzma_code returned LZMA_PROG_ERROR
Python stacktrace:
 [1] imagecodecs._lzma.lzma_encode
   @ imagecodecs/_lzma.pyx:137
Stacktrace:
 [1] pythrow()
   @ PythonCall.Core ~/.julia/packages/PythonCall/83z4q/src/Core/err.jl:77
 [2] errcheck
   @ ~/.julia/packages/PythonCall/83z4q/src/Core/err.jl:10 [inlined]
 [3] pycallargs(f::Py, args::Py)
   @ PythonCall.Core ~/.julia/packages/PythonCall/83z4q/src/Core/builtins.jl:194
 [4] pycall(f::Py, args::Vector{UInt8}; kwargs::@Kwargs{})
   @ PythonCall.Core ~/.julia/packages/PythonCall/83z4q/src/Core/builtins.jl:213
 [5] pycall
   @ ~/.julia/packages/PythonCall/83z4q/src/Core/builtins.jl:203 [inlined]
 [6] (::Py)(args::Vector{UInt8})
   @ PythonCall.Core ~/.julia/packages/PythonCall/83z4q/src/Core/Py.jl:363
 [7] top-level scope
   @ REPL[8]:1

Your system

julia> versioninfo()
Julia Version 1.12.3
Commit 966d0af0fdf (2025-12-15 11:20 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 9800X3D 8-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, znver5)
  GC: Built with stock GC
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)
Environment:
  JULIA_NUM_THREADS = 1

julia> Pkg.status()
Status `/tmp/jl_bFSaIh/Project.toml`
  [992eb4ea] CondaPkg v0.2.33
  [6099a3de] PythonCall v0.9.31

julia> CondaPkg.status()
CondaPkg Status /tmp/jl_bFSaIh/CondaPkg.toml
Environment
  /tmp/jl_bFSaIh/.CondaPkg/.pixi/envs/default
Pip Packages
  imagecodecs v2025.11.11

Activity

  1. added
    bugSomething isn't working
    on Dec 17, 2025
  2. added
    bugSomething isn't working
    and removed
    bugSomething isn't working
    on Dec 17, 2025
  3. cjdoris commented on Dec 17, 2025

    @cjdoris
    Member

    What is pytype(Py(UInt8[])) in the working/non-working cases.

    Do you still see the error if you start Julia with -t1?

    Is the version of imagecodecs the same in the working/non-working cases?

  4. nhz2 commented on Dec 18, 2025

    @nhz2
    ContributorAuthor
    julia> pytype(Py(UInt8[]))
    Python: <class 'juliacall.VectorValue'>

    In both cases. I have JULIA_NUM_THREADS = 1 env variable set.

    Interestingly, it sometimes does work on 1.12.3 if I repeat the import four times:

    using Pkg
    Pkg.activate(;temp=true)
    pkg"add PythonCall CondaPkg"
    using CondaPkg
    pkg"conda pip_add imagecodecs"
    using PythonCall
    imcd = pyimport("imagecodecs")
    imcd = pyimport("imagecodecs")
    imcd = pyimport("imagecodecs")
    imcd = pyimport("imagecodecs")
    imcd.lzma_encode(UInt8[])
  5. cjdoris commented on Dec 18, 2025

    @cjdoris
    Member

    Ok that's very strange. That hints at a more fundamental bug.

    Try this?

    x = Py(UInt8[])
    imcd.lzma_encode(x)
  6. nhz2 commented on Jul 1, 2026

    @nhz2
    ContributorAuthor

    With help from Claude and Codex I finally think I know what is going on here.

    https://github.com/JuliaPackaging/Yggdrasil/blob/master/L/LibUnwind/LibUnwind%401.8.3/bundled/patches/libunwind-configure-static-lzma.patch

    Julia is statically compiling its own internal version of lzma. However it is not the complete liblzma, just a few bits. For some reason I don't understand some of those bits of liblzma in julia leak out and shadow some bits from the full liblzma loaded by the python package.

    The result is that the version of liblzma that initializes the encoder is different from the version of liblzma that runs the encoder.

  7. cjdoris commented on Jul 1, 2026

    @cjdoris
    Member

    What happens if you run this on each version of Julia?

    @ccall lzma_version_number()::UInt32
  8. nhz2 commented on Jul 1, 2026

    @nhz2
    ContributorAuthor

    1.11.9:
    50040042
    1.12.6:
    50020052
    1.13.0-rc1:
    50080012

    So it looks like 1.12 is using a much older version of liblzma

  9. nhz2 commented on Jul 3, 2026

    @nhz2
    ContributorAuthor

    I've tested julia 1.12 with the libunwind .so files from JuliaPackaging/Yggdrasil#14113 and that fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions