Repository navigation
Trouble when using a sysimage with PythonCall #129
Copy link
Copy link
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
I'm having trouble when building a sysimage with PythonCall-- or rather, I can built it OK, but then when I use it, like
julia --project=myproject --sysimage=mysysimage.so -e "using Pkg; Pkg.instantiate()"I get
#29 92.79 fatal: error thrown and no exception handler available.
#29 92.79 InitError(mod=:C, error=ErrorException("no environment in the LOAD_PATH depends on CondaPkg"))
#29 92.84 error at ./error.jl:33
#29 92.84 _jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
#29 92.84 jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
#29 92.84 _resolve_top_env at /root/.julia/packages/CondaPkg/GoPlj/src/resolve.jl:16
#29 92.84 _jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
#29 92.84 jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
#29 92.84 #resolve#17 at /root/.julia/packages/CondaPkg/GoPlj/src/resolve.jl:222
#29 92.84 _jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
#29 92.84 jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
#29 92.84 resolve at /root/.julia/packages/CondaPkg/GoPlj/src/resolve.jl:209
#29 92.84 _jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
#29 92.84 jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
#29 92.84 envdir at /root/.julia/packages/CondaPkg/GoPlj/src/env.jl:66
#29 92.85 init_context at /root/.julia/packages/PythonCall/Z6DIG/src/cpython/context.jl:56
#29 92.86 __init__ at /root/.julia/packages/PythonCall/Z6DIG/src/cpython/CPython.jl:21
#29 92.87 jfptr___init___72494 at /deps.so (unknown line)
#29 92.87 _jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
#29 92.87 jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
#29 92.87 jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
#29 92.87 jl_module_run_initializer at /buildworker/worker/package_linux64/build/src/toplevel.c:73
#29 92.87 _finish_julia_init at /buildworker/worker/package_linux64/build/src/init.c:796
#29 92.87 julia_init at /buildworker/worker/package_linux64/build/src/init.c:730
#29 92.87 jl_repl_entrypoint at /buildworker/worker/package_linux64/build/src/jlapi.c:695
#29 92.87 main at /buildworker/worker/package_linux64/build/cli/loader_exe.c:42
#29 92.88 __libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
#29 92.88 _start at /usr/local/julia/bin/julia (unknown line)
#29 93.11 ERROR: Failed to precompile MyPackage [...redacted...]
#29 94.21 Stacktrace:
#29 94.21 [1] error(s::String)
#29 94.60 @ Base ./error.jl:33
#29 94.77 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, ignore_loaded_modules::Bool)
#29 94.77 @ Base ./loading.jl:1466
#29 94.77 [3] compilecache(pkg::Base.PkgId, path::String)
#29 94.78 @ Base ./loading.jl:1410
#29 94.78 [4] _require(pkg::Base.PkgId)
#29 94.78 @ Base ./loading.jl:1120
#29 94.78 [5] require(uuidkey::Base.PkgId)
#29 94.78 @ Base ./loading.jl:1013
#29 94.78 [6] require(into::Module, mod::Symbol)
#29 94.78 @ Base ./loading.jl:997(please excuse the #29 92.79 stuff, I'm in a dockerfile here).
I believe the issue is that PythonCall's __init__ tries to resolve the CondaPkg environment, but when a module is in a sysimage, that __init__ occurs at startup time (i.e. when julia itself is starting up), and at that point in the process the package environment isn't setup yet... or something like that.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed
Activity
cjdoris commentedon Mar 8, 2022
You're saying
__init__is being called beforeLOAD_PATHis set? Surely that can't be right, it's a documented variable inBase, andBasemust have already initialised? Can you inject some code somewhere to print out theLOAD_PATHto check if this is the case?ericphanson commentedon Mar 11, 2022
I tried adding
println(Base.load_path())to the first line of PythonCall's__init__, but for some reason that didn't print:KristofferC commentedon Mar 11, 2022
Works for me:
Due to the way these packages seem structured make sure that you are using the same project as that you created the sysimage with.
ericphanson commentedon Mar 11, 2022
Ah ok, I was not doing that-- on purpose, because I want to build a sysimage w/ all dependencies but not my package code, so I don't need to rebuild the sysimage every time I change the code I'm working on. (Basically this strategy: https://github.com/beacon-biosignals/julia_pod/blob/94a91696ed68e97d7749ccb5659ed22c0d27b048/add_me_to_your_PATH/Dockerfile.template#L4-L16).
edit: but in my non-MWE, I was also copying over the CondaPkg.toml and including CondaPkg in the sysimage, so even though it's not the exact same project environment, it seems like it should be able to work still?
cjdoris commentedon Apr 12, 2022
Did you ever resolve this? I guess like the error says you need to ensure that CondaPkg is actually a dependency of something in your LOAD_PATH.
YuliyaCl commentedon Apr 12, 2022
The same error occurs when I'm trying to run app.exe (created with
PackageCompiler.create_app)ericphanson commentedon Apr 12, 2022
No, I just removed PythonCall from my sysimage as a workaround for now.
Hm, I thought I had that, but maybe not.
glennmoy commentedon Jul 3, 2023
Logging for posterity as I'm hitting the issue from the other direction: building a sysimage in julia then trying to execute it via
juliacall.MWE - inside a virtual env
juliapkg.json:
and then trying to load from a python session:
github-actions commentedon Sep 11, 2023
This issue has been marked as stale because it has been open for 30 days with no activity. If the issue is still relevant then please leave a comment, or else it will be closed in 7 days.
ericphanson commentedon Sep 11, 2023
I believe this is not stale (and autoclose bots are annoying).
Specifically, I think this is the current state:
That could be considered an acceptable state of affairs (esp. if pkgimages mean sysimages are less relevant) but it can be very confusing to run into and I think unless it's clearly documented somewhere (or fixed) the issue should stay open. (in my opinion).
cjdoris commentedon Sep 13, 2023
I'm not quite sure what you mean by "final environment"?
TBH I'm really (really really) not an expert in sysimages so I can't help much. The error (as far as CondaPkg sees it) is that your
LOAD_PATH(at the time the package is loaded) does not have any entries depending on CondaPkg - which should not happen because you're loading CondaPkg from somewhere in your environment. So presumably some sysimage thing is messing that up - at which point my expertise stops and you'll have to figure out why.cjdoris commentedon Sep 13, 2023
(I agree autoclose bots are annoying, but it's also annoying and stressful for me to have more open issues than I can deal with sat there with no activity. The bot is simply a way to spread the load a bit - either the person who wrote the issue can help out a bit to fix the problem, or if they don't care enough then the issue may as well be closed. I've updated the text the bot uses to be a little less cold.)
cjdoris commentedon Sep 13, 2023
If you think the issue is alleviated by better documentation, feel free to open a PR on
docs/src/faq.md.ericphanson commentedon Sep 14, 2023
I think this might be basically the issue.
I am also not a sysimage expert, but I think it could be that when you add a package into a sysimage, you're essentially loading the package as normal, and then later serializing out the entire state of your julia session, loaded packages and all. So it could be that
__init__time is when the package is being added to the sysimage, which isn't really when we actually want to use the package; we want to use it later when we start our julia session (with the sysimage).So I think the code "fix" would be to not do this work at init time, but rather some other time (e.g. on the first call to any function that needs to do something w/ python).
I think the docs "fix" would be a FAQ question like you said, and maybe that's preferable.
ericphanson commentedon Sep 14, 2023
Actually I'm not sure my explanation is accurate, re-reading the original issue again... Since the error occurs later, once we start to use the sysimage. So I am lost as to the exact issue. But maybe I can still try to add a FAQ entry