Hi Colin,
Maybe this is not the approach you’re after, but you could just use @pyinclude(ENV["PYTHONSTARTUP"])
.
For a Python startup file containing
import sys
sys.path = ["FromStartup"]
(the path of which is contained in the environment variable PYTHONSTARTUP
), I get
using PyCall
sys = pyimport("sys")
println(length(sys.path)) # 6, i.e. not just ["FromStartup"]
@pyinclude(ENV["PYTHONSTARTUP"])
println(sys.path) # ["FromStartup"]
Nowadays PythonCall.jl seems to be preferred over PyCall.jl. As far as I can tell there is no equivalent to @pyinclude
, but you could use something like
# (After restarting)
using PythonCall
sys = pyimport("sys")
println(length(sys.path)) # 6
# So also PythonCall.jl does not run the startup file automatically
@pyexec (path=ENV["PYTHONSTARTUP"]) =>
"""
with open(path) as f:
exec(f.read())
"""
println(sys.path) # ['FromStartup']