@@ -52,6 +52,11 @@ function init_context()
5252 if exe_path == " " || exe_path == " @CondaPkg"
5353 # By default, we use Python installed by CondaPkg.
5454 exe_path = Sys. iswindows () ? joinpath (CondaPkg. envdir (), " python.exe" ) : joinpath (CondaPkg. envdir (), " bin" , " python" )
55+ # It's not sufficient to only activate the env while Python is initialising,
56+ # it must also be active when loading extension modules (e.g. numpy). So we
57+ # activate the environment globally.
58+ # TODO : is this really necessary?
59+ CondaPkg. activate! (ENV )
5560 CTX. which = :CondaPkg
5661 elseif exe_path == " @PyCall"
5762 # PyCall compatibility mode
@@ -66,12 +71,9 @@ function init_context()
6671 CTX. which = :unknown
6772 end
6873
69- # Call f() in a suitable environment for running Python
70- withenv (f) = CTX. which == :CondaPkg ? CondaPkg. withenv (f) : f ()
71-
7274 # Ensure Python is runnable
7375 try
74- withenv (() -> run (pipeline (` $exe_path --version` , stdout = devnull , stderr = devnull ) ))
76+ run (pipeline (` $exe_path --version` , stdout = devnull , stderr = devnull ))
7577 catch
7678 error (" Python executable $(repr (exe_path)) is not executable." )
7779 end
@@ -91,16 +93,16 @@ function init_context()
9193 Some (nothing )
9294 )
9395 if lib_path != = nothing
94- lib_ptr = withenv (() -> dlopen_e (lib_path, CTX. dlopen_flags) )
96+ lib_ptr = dlopen_e (lib_path, CTX. dlopen_flags)
9597 if lib_ptr == C_NULL
9698 error (" Python library $(repr (lib_path)) could not be opened." )
9799 else
98100 CTX. lib_path = lib_path
99101 CTX. lib_ptr = lib_ptr
100102 end
101103 else
102- for lib_path in withenv (() -> readlines (python_cmd ([joinpath (@__DIR__ , " find_libpython.py" ), " --list-all" ]) ))
103- lib_ptr = withenv (() -> dlopen_e (lib_path, CTX. dlopen_flags) )
104+ for lib_path in readlines (python_cmd ([joinpath (@__DIR__ , " find_libpython.py" ), " --list-all" ]))
105+ lib_ptr = dlopen_e (lib_path, CTX. dlopen_flags)
104106 if lib_ptr == C_NULL
105107 @warn " Python library $(repr (lib_path)) could not be opened."
106108 else
@@ -148,7 +150,7 @@ function init_context()
148150 sys.stdout.write(sys.exec_prefix)
149151 """
150152 end
151- CTX. pyprogname, CTX. pyhome = withenv (() -> readlines (python_cmd ([" -c" , script]) ))
153+ CTX. pyprogname, CTX. pyhome = readlines (python_cmd ([" -c" , script]))
152154
153155 # Set PythonHome
154156 CTX. pyhome_w = Base. cconvert (Cwstring, CTX. pyhome)
0 commit comments