@@ -52,6 +52,11 @@ function init_context()
52
52
if exe_path == " " || exe_path == " @CondaPkg"
53
53
# By default, we use Python installed by CondaPkg.
54
54
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 )
55
60
CTX. which = :CondaPkg
56
61
elseif exe_path == " @PyCall"
57
62
# PyCall compatibility mode
@@ -66,12 +71,9 @@ function init_context()
66
71
CTX. which = :unknown
67
72
end
68
73
69
- # Call f() in a suitable environment for running Python
70
- withenv (f) = CTX. which == :CondaPkg ? CondaPkg. withenv (f) : f ()
71
-
72
74
# Ensure Python is runnable
73
75
try
74
- withenv (() -> run (pipeline (` $exe_path --version` , stdout = devnull , stderr = devnull ) ))
76
+ run (pipeline (` $exe_path --version` , stdout = devnull , stderr = devnull ))
75
77
catch
76
78
error (" Python executable $(repr (exe_path)) is not executable." )
77
79
end
@@ -91,16 +93,16 @@ function init_context()
91
93
Some (nothing )
92
94
)
93
95
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)
95
97
if lib_ptr == C_NULL
96
98
error (" Python library $(repr (lib_path)) could not be opened." )
97
99
else
98
100
CTX. lib_path = lib_path
99
101
CTX. lib_ptr = lib_ptr
100
102
end
101
103
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)
104
106
if lib_ptr == C_NULL
105
107
@warn " Python library $(repr (lib_path)) could not be opened."
106
108
else
@@ -148,7 +150,7 @@ function init_context()
148
150
sys.stdout.write(sys.exec_prefix)
149
151
"""
150
152
end
151
- CTX. pyprogname, CTX. pyhome = withenv (() -> readlines (python_cmd ([" -c" , script]) ))
153
+ CTX. pyprogname, CTX. pyhome = readlines (python_cmd ([" -c" , script]))
152
154
153
155
# Set PythonHome
154
156
CTX. pyhome_w = Base. cconvert (Cwstring, CTX. pyhome)
0 commit comments