Skip to content

System image compilation and --compiled-modules=no is broken in Python >= 3.9 #459

@tkf

Description

@tkf

In Python >= 3.9, Julia(compiled_modules=False) fails with

JuliaError: Exception 'LoadError' occurred while calling julia code:
const PyCall = Base.require(Base.PkgId(Base.UUID("438e738f-606a-5dbb-bf0a-cddfbfd45ab0"), "PyCall"))

With Julia(debug=True, compiled_modules=False), it shows

┌ Error: Failed to import PyCall
│   exception =
│    LoadError: could not load symbol "main":
│    /.../bin/python: undefined symbol: main
│    Stacktrace:
│      [1] #dlsym#1
│        @ ./libdl.jl:59 [inlined]
│      [2] dlsym(hnd::Ptr{Nothing}, s::Symbol)
│        @ Base.Libc.Libdl ./libdl.jl:57
│      [3] top-level scope
│        @ ~/.julia/packages/PyCall/ScKXc/src/startup.jl:76
│      [4] include(mod::Module, _path::String)
│        @ Base ./Base.jl:420
│      [5] include(x::String)
│        @ PyCall ~/.julia/packages/PyCall/ScKXc/src/PyCall.jl:1
│      [6] top-level scope
│        @ ~/.julia/packages/PyCall/ScKXc/src/PyCall.jl:38
│      [7] include
│        @ ./Base.jl:420 [inlined]
│      [8] _require(pkg::Base.PkgId)
│        @ Base ./loading.jl:1149
│      [9] require(uuidkey::Base.PkgId)
│        @ Base ./loading.jl:1013
│     [10] top-level scope
│        @ none:3
│    in expression starting at /home/runner/.julia/packages/PyCall/ScKXc/src/startup.jl:41
│    in expression starting at /home/runner/.julia/packages/PyCall/ScKXc/src/PyCall.jl:1
└ @ Main none:5

Note that lines 41 to 76 as mentioned in the stack trace have this code:

    41  if !symbols_present
    42      # Python not present. Use deps.jl
...
    58  else
    59      @static if Sys.iswindows()
...
    72      else
    73          libpy_handle = proc_handle
    74          # Now determine the name of the python library that these symbols are from
    75          some_address_in_libpython = Libdl.dlsym(libpy_handle, :Py_GetVersion)
    76          some_address_in_main_exe = Libdl.dlsym(proc_handle, Sys.isapple() ? :_mh_execute_header : :main)

--- https://github.com/JuliaPy/PyCall.jl/blob/4e5c12cfc597a0e911d42fe661aabd4f1cd74a5f/src/startup.jl#L41-L76

Since the system image compilation script uses --compiled-modules=no for Julia >= 1.5, this also breaks python3 -m julia.sysimage sys.so.

For full traces of this failure mode in CI, see: #458 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions