Skip to content

Instantly share code, notes, and snippets.

@tkf
Last active November 9, 2018 06:11
Show Gist options
  • Save tkf/871c893d8bebf6741e10ee14f46c30fe to your computer and use it in GitHub Desktop.
Save tkf/871c893d8bebf6741e10ee14f46c30fe to your computer and use it in GitHub Desktop.
.PHONY: run
JULIA = julia --startup-file=no
run: py
-$(JULIA) PIEPyCall-0.jl
$(JULIA) PIEPyCall-1.jl
$(JULIA) PIEPyCall-2.jl
py:
conda create --prefix py defaults::python
module PIEPyCall
using Libdl
const pyhome = abspath("py")
const libpython = "$pyhome/bin/python3"
const wPYTHONHOME = Base.cconvert(Cwstring, string(pyhome, ':', pyhome))
const wpyprogramname = Base.cconvert(Cwstring, libpython)
function __init__()
h = Libdl.dlopen(libpython, Libdl.RTLD_LAZY|Libdl.RTLD_GLOBAL)
@show unsafe_string(ccall((:Py_GetVersion, libpython), Ptr{UInt8}, ()))
@show ccall((:Py_IsInitialized, libpython), Cint, ())
ccall((:Py_SetProgramName, libpython), Cvoid, (Ptr{Cwchar_t},), wpyprogramname)
ccall((:Py_SetPythonHome, libpython), Cvoid, (Ptr{Cwchar_t},), wPYTHONHOME)
ccall((:Py_InitializeEx, libpython), Cvoid, (Cint,), 0)
@show ccall((:Py_IsInitialized, libpython), Cint, ())
end
end
module PIEPyCall
using Libdl
const pyhome = abspath("py")
const libpython = "$pyhome/bin/python3"
const wPYTHONHOME = Base.cconvert(Cwstring, string(pyhome, ':', pyhome))
const wpyprogramname = Base.cconvert(Cwstring, libpython)
# function __init__()
h = Libdl.dlopen(libpython, Libdl.RTLD_LAZY|Libdl.RTLD_GLOBAL)
@show unsafe_string(ccall((:Py_GetVersion, libpython), Ptr{UInt8}, ()))
@show ccall((:Py_IsInitialized, libpython), Cint, ())
ccall((:Py_SetProgramName, libpython), Cvoid, (Ptr{Cwchar_t},), wpyprogramname)
ccall((:Py_SetPythonHome, libpython), Cvoid, (Ptr{Cwchar_t},), wPYTHONHOME)
ccall((:Py_InitializeEx, libpython), Cvoid, (Cint,), 0)
@show ccall((:Py_IsInitialized, libpython), Cint, ())
# end
end
module PIEPyCall
using Libdl
const pyhome = abspath("py")
const libpython = "$pyhome/bin/python3"
const wPYTHONHOME = Base.cconvert(Cwstring, string(pyhome, ':', pyhome))
const wpyprogramname = Base.cconvert(Cwstring, libpython)
function __init__()
h = Libdl.dlopen(libpython, Libdl.RTLD_LAZY|Libdl.RTLD_GLOBAL)
@show unsafe_string(ccall(Libdl.dlsym(h, :Py_GetVersion), Ptr{UInt8}, ()))
@show ccall(Libdl.dlsym(h,:Py_IsInitialized), Cint, ())
ccall(Libdl.dlsym(h,:Py_SetProgramName), Cvoid, (Ptr{Cwchar_t},), wpyprogramname)
ccall(Libdl.dlsym(h,:Py_SetPythonHome), Cvoid, (Ptr{Cwchar_t},), wPYTHONHOME)
ccall(Libdl.dlsym(h,:Py_InitializeEx), Cvoid, (Cint,), 0)
@show ccall(Libdl.dlsym(h,:Py_IsInitialized), Cint, ())
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment