Repository navigation
Description
This is a duplicate of #68, but that issue seemed quite buried and this seems rather important, also I thought I'd provide a more specific title. (Please forgive me muddling up the issues postings!)
Anyway, when using pyjulia for the very first time, here is the segfault which occurs:
InitError(:PyCall,PyError (:PyImport_ImportModule) <class 'SystemError'>
SystemError('initialization of _opcode did not return an extension module',)
signal (11): Segmentation fault
while loading no file, in expression starting on line 0
PyObject_Call at /usr/lib/x86_64-linux-gnu/libpython3.5m.so (unknown line)
macro expansion at /home/savastio/.julia/v0.5/PyCall/src/exception.jl:78 [inlined]
#_pycall#66 at /home/savastio/.julia/v0.5/PyCall/src/PyCall.jl:551
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1392 [inlined]
jl_f__apply at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:547
_pycall at /home/savastio/.julia/v0.5/PyCall/src/PyCall.jl:539
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1392 [inlined]
jl_f__apply at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:547
#pycall#69 at /home/savastio/.julia/v0.5/PyCall/src/PyCall.jl:570
show at /home/savastio/.julia/v0.5/PyCall/src/exception.jl:39
unknown function (ip: 0x7f6ef00f60a6)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
show_default at ./show.jl:130
unknown function (ip: 0x7f6ef00f4aa6)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
show at ./show.jl:116
unknown function (ip: 0x7f6ef00f4506)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:210 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1392 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1950
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1392 [inlined]
jl_show at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:972
ffi_call_unix64 at /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so (unknown line)
ffi_call at /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so (unknown line)
_ctypes_callproc at /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so (unknown line)
unknown function (ip: 0x7f6ef35e1fca)
PyObject_Call at /usr/bin/python3 (unknown line)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
PyEval_EvalCodeEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x4ebd37)
PyObject_Call at /usr/bin/python3 (unknown line)
unknown function (ip: 0x4f413d)
PyObject_Call at /usr/bin/python3 (unknown line)
unknown function (ip: 0x54d358)
unknown function (ip: 0x55d17b)
PyObject_Call at /usr/bin/python3 (unknown line)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalCode at /usr/bin/python3 (unknown line)
unknown function (ip: 0x5c7b84)
PyCFunction_Call at /usr/bin/python3 (unknown line)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d82e)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
PyEval_EvalCodeEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x4ebdd6)
PyObject_Call at /usr/bin/python3 (unknown line)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalFrameEx at /usr/bin/python3 (unknown line)
unknown function (ip: 0x52d2e2)
PyEval_EvalCode at /usr/bin/python3 (unknown line)
unknown function (ip: 0x5fd2c1)
PyRun_FileExFlags at /usr/bin/python3 (unknown line)
PyRun_SimpleFileExFlags at /usr/bin/python3 (unknown line)
Py_Main at /usr/bin/python3 (unknown line)
main at /usr/bin/python3 (unknown line)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
_start at /usr/bin/python3 (unknown line)
This isn't exactly the same as #89, but it may be related.
The fix seems to be to somehow force PyCall to rebuild, doing a Pkg.rm followed by a Pkg.add seems like the most sure way. I thought just deleting PyCall.ji would be enough, but it doesn't seem to be working.
The error definitely occurs here, which is where using PyCall is invoked for the very first time. Calls to Julia not involving PyCall at this point, seem to work just fine. I can even do using other packages without any problems. The problem definitely seems to have something to do with PyCall. I'm still trying to figure out what.
If any Julia experts know what the hell the "initialization of _opcode" means, that would likely be very helpful.
Activity
ExpandingMan commentedon Mar 22, 2017
Update: Ok, I think I have established how to reliably fix this, though I don't know why it works. If you completely remove PyCall, then do
Pkg.add("PyCall")without recompiling it (e.g. don't dousing PyCallwithin Julia) but instead start up pyjulia and allow pyjulia to recompile PyCall, then pyjulia seems to work ok from then on. I've tried this on 3 different Ubuntu machines and it always seems to work.Update: I have traced down the error within PyCall and posted an issue here. The error definitely only occurs if PyCall was already compiled from within Julia. If you delete the
PyCall.jiand allow it to be compiled when pyjulia doesusing PyCallthe error disappears. I see that for some reason pyjulia uses separate binaries that are compiled into another cache directory. Is it possible that somehow ifPyCall.jiwas already compiled from within Julia that pyjulia attempts to use that binary and it is somehow incompatible?ExpandingMan commentedon Mar 22, 2017
I fixed it!
Ok, I really don't know if this is a permanent fix, as I suspect there is some reason that it wasn't already like this. The initialization of pyjulia adds its own directory to
LOAD_CACHE_PATH, but it doesn't remove the standard one. With both directories in there it finds a binary in the original one, attempts to use it, and crashes. If one removes the original directory by doingpop!(Base.LOAD_CACHE_PATH), pyjulia uses the proper binaries and seems to work just fine.If someone more knowledgeable comes along and confirms that this is likely what's going on, I'll make a pull request.
By the way, why are the regular Julia binaries incompatible with pyjulia in the first place? It's kind of unfortunate to have to recompile everything in order to use pyjulia.
stevengj commentedon Mar 22, 2017
See JuliaPy/PyCall.jl#219 (comment) and #51
stevengj commentedon Mar 22, 2017
In principle, we can use the regular precompiled Julia modules from pyjulia as long as they are modules that don't depend on PyCall (see also #89). In practice, that may be too much trouble to do reliably. Doing
pop!(Base.LOAD_CACHE_PATH)forces everything to be recompiled, but has the advantage of being simple and reliable.stevengj commentedon Mar 22, 2017
A simpler solution might be to just force a PyCall.ji file to exist in the pyjulia cache directory. This is already done if Python was statically linked. This should force recompilation of both PyCall and (I think) any module that depends on PyCall.
stevengj commentedon Mar 22, 2017
@ExpandingMan, can you try deleting all of your
.jicache files in both the regular Julia directory and the pyjulia cache directory, and then try:using PyCallin Julia)PyCall.jifile in the pyjulia cache path.pop!(Base.LOAD_CACHE_PATH)in pyjuliaExpandingMan commentedon Mar 22, 2017
Well, pyjulia already creates a blank
PyCall.jifile in the pyjulia cache path. So essentially what you've described above is what I've been doing and it causes a segfault. I have no idea what I'm talking about, but is it possible that Julia has somehow gotten smart enough to know that the blankPyCall.jiis just a blank file and then looks forPyCall.jiin the regular cache path?Am I correct in assuming that Julia checks directories for binaries in the order in which they are named in
LOAD_CACHE_PATH(and should stop looking once it finds one)?By the way, I checked if the
pop!statement fixes #89, since now pyjulia is being forced to use the newly compiled binaries. It doesn't.stevengj commentedon Mar 26, 2017
(Only if Python is statically linked.)
Hmm, I just looked at the Julia source code for loading the cache file, and unfortunately it seems that it looks at all the
PyCall.jifiles in all the cache-path directories, skipping any invalid/stale ones, and only recompiles if it doesn't find a valid one in any directory.So, it seems we have to temporarily replace the LOAD_CACHE_PATH with a single directory (not just
pop!, since there might be additional cache directories) if we want to force a recompile.rdeits commentedon Mar 28, 2017
Following your suggestions, I was able to get pyjulia working with the following changes: https://github.com/JuliaPy/pyjulia/compare/master...rdeits:7bfba98ad7?expand=1
ExpandingMan commentedon Mar 29, 2017
It seems to me that it would be nice if Julia provided some sort of low-level functionality for explicitly specifying which cache files you want to use only for specific modules. As far as I know, that functionality doesn't currently exist. In the meantime, it looks like there are two options for pyjulia: either use its own cache directory for everything, recompiling as it goes or switching the cache directory based on what module it's using. The first option seems clearly better to me, as I think the latter would be extremely error prone.
ExpandingMan commentedon Mar 30, 2017
(I never meant to close this issue, I hit the button on accident.)
I made the simplest pull request I could think of, #93. It's far from ideal, but it should fix the biggest issue blocking most users from using pyjulia.
Keno commentedon Aug 18, 2017
I've seen this before and it was related to mismatched python versions. I've fixed most of that, so please file a new issue if this re-occurs with the latest versions of pyjulia/PyCall.