Last active
November 9, 2018 06:11
-
-
Save tkf/871c893d8bebf6741e10ee14f46c30fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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