From a95568187a8b0d71b670b472eeeb3847e4f612c8 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 24 Sep 2020 23:09:47 -0700 Subject: [PATCH] Use PyPreferences --- Project.toml | 1 + src/PyCall.jl | 1 + src/startup.jl | 12 +++++++----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index f220698a..314d4036 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +PyPreferences = "cc9521c6-0242-4dda-8d66-c47a9d9eec02" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" VersionParsing = "81def892-9a0e-5fdd-b105-ffc91e053289" diff --git a/src/PyCall.jl b/src/PyCall.jl index c260bbd4..b9314db4 100644 --- a/src/PyCall.jl +++ b/src/PyCall.jl @@ -4,6 +4,7 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optle @eval Base.Experimental.@optlevel 1 end +using PyPreferences using VersionParsing export pycall, pycall!, pyimport, pyimport_e, pybuiltin, PyObject, PyReverseDims, diff --git a/src/startup.jl b/src/startup.jl index 1c182c0a..37413d94 100644 --- a/src/startup.jl +++ b/src/startup.jl @@ -38,17 +38,19 @@ else global symbols_present = hassym(proc_handle, :Py_GetVersion) end +if PyPreferences.inprocess + @assert symbols_present # TODO: better error +end + if !symbols_present - # Python not present. Use deps.jl - const depfile = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl") - isfile(depfile) || error("PyCall not properly installed. Please run Pkg.build(\"PyCall\")") - include(depfile) # generated by Pkg.build("PyCall") + PyPreferences.assert_configured() + using PyPreferences: PYTHONHOME, conda, libpython, pyprogramname, python, pyversion_build # Only to be used at top-level - pointer will be invalid after reload libpy_handle = try Libdl.dlopen(libpython, Libdl.RTLD_LAZY|Libdl.RTLD_DEEPBIND|Libdl.RTLD_GLOBAL) catch err if err isa ErrorException - error(err.msg, ". Please run `Pkg.build(\"PyCall\")` if your Python build has changed") + error(err.msg, "\n", PyPreferences.instruction_message()) else rethrow(err) end