Confused by behavior when changing ENV["PYTHONPATH"] in new module

mgalenb
Fri, 29 Sep 2023 18:48:01 +0000
General Usage

I am making a module (which has a local python env installed) and I am trying to add a path to ENV[“PYTHONPATH”] and then import a module I am hacking in

module Test

ENV["PYTHONPATH"]=joinpath(dirname(@__FILE__), "python/testpy")

using PyCall
const t = PyNULL()
function __init__()
    copy!(t,pyimport("testpy"))
end

end

However, this can’t find my testpy module and failed to compile.

If I leave out the __init__ function and instead do this

module Test

ENV["PYTHONPATH"]=joinpath(dirname(@__FILE__), "..", "python/testpy")

using PyCall
const t = PyNULL()

include("test.jl")

end

where `test.jl" is:

copy!(t,pyimport("testpy"))

println(t.something(x))

this works and prints out t.something(x). however when I open Julia REPL and do using Test then t is a PyNULL()

I am trying to install the python local to this Julia package (I know it makes the package huge, 1 GB to be exact) as I don’t want to use my user’s Conda environment. this breaks other python modules/scripts I am trying to wrap with Julia

essential, I don’t understand why the “PYTHONPATH” isn’t updated when the __init__ function runs… Suggestions are welcome!

1 post - 1 participant