Compile and use custom system image for PyJulia

Viewed 409

I tried to follow the instructions at this page to build a custom Julia system image, in order to speed up the initialization phase when using PyJulia. The command python3 -m julia.sysimage sys.so successfully builds a sys.so image, but then jl = Julia(sysimage="sys.so") seems to fail, since I still get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
  File "/home/jar/.local/lib/python3.7/site-packages/julia/core.py", line 248, in load_module
    elif self.julia.isafunction(juliapath):
  File "/home/jar/.local/lib/python3.7/site-packages/julia/core.py", line 239, in julia
    self.__class__.julia = julia = Julia()
  File "/home/jar/.local/lib/python3.7/site-packages/julia/core.py", line 483, in __init__
    raise UnsupportedPythonError(jlinfo)
julia.core.UnsupportedPythonError: It seems your Julia and PyJulia setup are not supported.

Julia executable:
    julia
Python interpreter and libpython used by PyCall.jl:
    /usr/bin/python3
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
Python interpreter used to import PyJulia and its libpython.
    /usr/bin/python3.7
    None

Your Python interpreter "/usr/bin/python3.7"
is statically linked to libpython.  Currently, PyJulia does not fully
support such Python interpreter.

which is the same issue I am trying to solve by compiling this custom image in the first place. What am I doing wrong? I would like to avoid the Julia(compiled_modules=False) workaround, because it takes literally forever.

1 Answers

It seems related to this issue, and the following workaround to load the custom image seems to work:

from julia.api import LibJulia
api = LibJulia.load()
api.sysimage = "PATH/TO/CUSTOM/sys.so"
api.init_julia()

from julia import Main
Related