Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
* Bug fix: preserve the selected Python executable when embedding Python 3.10 on Windows.
* Bug fix: avoid precompilation cache miss when `check_bounds` option set.
* Bug fix: `juliacall` set the environment variable `JULIA_PYTHONCALL_EXECUTABLE`
instead of `JULIA_PYTHONCALL_EXE`, so child Julia processes resolved a new
Expand Down
31 changes: 31 additions & 0 deletions pytest/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@ def test_import():
import juliacall


def test_pythoncall_executable_runs_python():
import subprocess
import sys

from juliacall import Main as jl

code = '''\
using PythonCall
sys = pyimport("sys")
@assert pyconvert(String, sys.executable) == only(ARGS)
subprocess = pyimport("subprocess")
output = subprocess.check_output([sys.executable, "-c", "print(6, end='')"])
print(pyconvert(String, output.decode()))
'''
result = subprocess.run(
[
str(jl.seval("first(Base.julia_cmd().exec)")),
"--project=" + str(jl.seval("dirname(Base.active_project())")),
"--startup-file=no",
"-e",
code,
sys.executable,
],
capture_output=True,
text=True,
timeout=180,
)
assert result.returncode == 0, result.stderr
assert result.stdout == "6"


def test_newmodule():
import juliacall

Expand Down
10 changes: 10 additions & 0 deletions src/C/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ function init_context()
CTX.pyprogname_w = Base.cconvert(Cwstring, CTX.pyprogname)
Py_SetProgramName(pointer(CTX.pyprogname_w))

# Python 3.10 on Windows ignores program_name when resolving the executable.
if Sys.iswindows() && startswith(Base.unsafe_string(Py_GetVersion()), "3.10.")
ccall(
dlsym(CTX.lib_ptr, :_Py_SetProgramFullPath),
Cvoid,
(Ptr{Cwchar_t},),
pointer(CTX.pyprogname_w),
)
end

# Start the interpreter and register exit hooks
Py_InitializeEx(0)
atexit() do
Expand Down
Loading