Skip to content

Commit 1340044

Browse files
Fix embedded Python executable on Windows 3.10 (#820)
* Reproduce embedded Python executable selection on Windows Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com> * Set the embedded Python executable on Windows 3.10 Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com> * Record executable initialization fix and remove diagnostic workflow Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com> * Verify PySR worker behavior across interpreter fixes Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com> * Install PySR test dependencies in worker comparison * Remove completed Windows comparison workflow Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com> --------- Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
1 parent 3f23e2c commit 1340044

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
* Bug fix: preserve the selected Python executable when embedding Python 3.10 on Windows.
45
* Bug fix: avoid precompilation cache miss when `check_bounds` option set.
56
* Bug fix: `juliacall` set the environment variable `JULIA_PYTHONCALL_EXECUTABLE`
67
instead of `JULIA_PYTHONCALL_EXE`, so child Julia processes resolved a new

‎pytest/test_all.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@ def test_import():
55
import juliacall
66

77

8+
def test_pythoncall_executable_runs_python():
9+
import subprocess
10+
import sys
11+
12+
from juliacall import Main as jl
13+
14+
code = '''\
15+
using PythonCall
16+
sys = pyimport("sys")
17+
@assert pyconvert(String, sys.executable) == only(ARGS)
18+
subprocess = pyimport("subprocess")
19+
output = subprocess.check_output([sys.executable, "-c", "print(6, end='')"])
20+
print(pyconvert(String, output.decode()))
21+
'''
22+
result = subprocess.run(
23+
[
24+
str(jl.seval("first(Base.julia_cmd().exec)")),
25+
"--project=" + str(jl.seval("dirname(Base.active_project())")),
26+
"--startup-file=no",
27+
"-e",
28+
code,
29+
sys.executable,
30+
],
31+
capture_output=True,
32+
text=True,
33+
timeout=180,
34+
)
35+
assert result.returncode == 0, result.stderr
36+
assert result.stdout == "6"
37+
38+
839
def test_newmodule():
940
import juliacall
1041

‎src/C/context.jl‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ function init_context()
278278
CTX.pyprogname_w = Base.cconvert(Cwstring, CTX.pyprogname)
279279
Py_SetProgramName(pointer(CTX.pyprogname_w))
280280

281+
# Python 3.10 on Windows ignores program_name when resolving the executable.
282+
if Sys.iswindows() && startswith(Base.unsafe_string(Py_GetVersion()), "3.10.")
283+
ccall(
284+
dlsym(CTX.lib_ptr, :_Py_SetProgramFullPath),
285+
Cvoid,
286+
(Ptr{Cwchar_t},),
287+
pointer(CTX.pyprogname_w),
288+
)
289+
end
290+
281291
# Start the interpreter and register exit hooks
282292
Py_InitializeEx(0)
283293
atexit() do

0 commit comments

Comments
 (0)