diff --git a/deps/build.jl b/deps/build.jl index 762c8724..030b1af8 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -189,7 +189,7 @@ const programname = pysys(python, "executable") # Get PYTHONHOME, either from the environment or from Python # itself (if it is not in the environment or if we are using Conda) -PYTHONHOME = if !haskey(ENV, "PYTHONHOME") || use_conda +PYTHONHOME = if use_conda # PYTHONHOME tells python where to look for both pure python # and binary modules. When it is set, it replaces both # `prefix` and `exec_prefix` and we thus need to set it to @@ -200,7 +200,7 @@ PYTHONHOME = if !haskey(ENV, "PYTHONHOME") || use_conda exec_prefix = pysys(python, "exec_prefix") is_windows() ? exec_prefix : pysys(python, "prefix") * ":" * exec_prefix else - ENV["PYTHONHOME"] + get(ENV, "PYTHONHOME", nothing) end # cache the Python version as a Julia VersionNumber @@ -238,8 +238,8 @@ writeifchanged("deps.jl", """ const pyprogramname = "$(escape_string(programname))" const wpyprogramname = $(wstringconst(programname)) const pyversion_build = $(repr(pyversion)) - const PYTHONHOME = "$(escape_string(PYTHONHOME))" - const wPYTHONHOME = $(wstringconst(PYTHONHOME)) + const PYTHONHOME = $(PYTHONHOME == nothing ? nothing : "\"" * escape_string(PYTHONHOME) * "\"") + const wPYTHONHOME = $(PYTHONHOME == nothing ? nothing : wstringconst(PYTHONHOME)) "True if we are using the Python distribution in the Conda package." const conda = $use_conda diff --git a/src/pyinit.jl b/src/pyinit.jl index 24565803..d65b0c71 100644 --- a/src/pyinit.jl +++ b/src/pyinit.jl @@ -31,7 +31,7 @@ function __init__() already_inited = 0 != ccall((@pysym :Py_IsInitialized), Cint, ()) if !already_inited - Py_SetPythonHome(libpy_handle, PYTHONHOME, wPYTHONHOME, pyversion) + PYTHONHOME != nothing && Py_SetPythonHome(libpy_handle, PYTHONHOME, wPYTHONHOME, pyversion) if !isempty(pyprogramname) if pyversion.major < 3 ccall((@pysym :Py_SetProgramName), Void, (Cstring,), pyprogramname) diff --git a/src/startup.jl b/src/startup.jl index 35c88731..733a60cb 100644 --- a/src/startup.jl +++ b/src/startup.jl @@ -47,7 +47,7 @@ if !symbols_present # Only to be used at top-level - pointer will be invalid after reload libpy_handle = Libdl.dlopen(libpython, Libdl.RTLD_LAZY|Libdl.RTLD_DEEPBIND|Libdl.RTLD_GLOBAL) # need SetPythonHome to avoid warning, #299 - Py_SetPythonHome(libpy_handle, PYTHONHOME, wPYTHONHOME, pyversion_build) + PYTHONHOME != nothing && Py_SetPythonHome(libpy_handle, PYTHONHOME, wPYTHONHOME, pyversion_build) else @static if is_windows() pathbuf = Vector{UInt16}(1024)