Skip to content

Fix detection of bundled python in PythonScriptingProvider - #8542

Merged
negasora merged 1 commit into
devfrom
test_fix_bundled_python_detection
Oct 12, 2026
Merged

negasora merged 1 commit into
devfrom
test_fix_bundled_python_detection

Conversation

@negasora

Copy link
Copy Markdown
Member

No description provided.

@negasora negasora self-assigned this Sep 10, 2026

@fuzyll fuzyll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, thanks! I think this could potentially be further improved (and I have an idea in a code comment), but I see no reason this should be held up any longer than it already has been.

if not python_lib and not use_bundled_python:
if not sys.executable:
return (None, "Failed to find the python binary for the running interpreter")
return (sys.executable, "Success")

@fuzyll fuzyll Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debated requesting changes here because it feels like we should be doing more checks here. Does sys.executable exist? Is it executable? Is it an accepted version? Does it respond to -c or -m pip or other switches that we use?

Some of these are probably redundant. (I'm not sure how you would get here with a sys.executable that doesn't exist or isn't executable.) Others are probably only relevant if you're in an embedded Python from another application, which is not typically how people use us.

When I started trying to sketch out what this would look like, I realized ensuring some of these things would be pretty complicated. And, I would hope that setting this to something that doesn't work would fail fairly quickly for the user such that they would understand what the likely source of the failures is.

If you want to do any of that here, I still think it would be a good idea. But, I don't think holding this up over it is a good move.

@negasora
negasora force-pushed the test_fix_bundled_python_detection branch from 293d093 to 1914232 Compare October 12, 2026 20:58
@negasora
negasora merged commit 1914232 into dev Oct 12, 2026
5 checks passed
@negasora
negasora deleted the test_fix_bundled_python_detection branch October 12, 2026 20:59
@fuzyll

fuzyll commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

For extra context, since I had forgotten by the time I came back from PTO: This was to address an issue from an Enterprise customer that was trying to configure Binary Ninja in a Docker container. When running headless, they did not have python.interpreter set and Binary Ninja was just dying in the scripting provider:

File "/opt/binaryninja/python/binaryninja/scriptingprovider.py", line 1330, in _get_executable_for_libpython
    python_bin_version = self._bin_version(python_bin, python_env=python_env)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/binaryninja/python/binaryninja/scriptingprovider.py", line 1268, in _bin_version
    return self._run_args([
           ^^^^^^^^^^^^^^^^
  File "/opt/binaryninja/python/binaryninja/scriptingprovider.py", line 1246, in _run_args
    return (True, subprocess.check_output(args, startupinfo=si, stderr=subprocess.STDOUT, env=env).decode("utf-8"))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.12/subprocess.py", line 1955, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/opt/binaryninja/python/binaryninja/../../plugins/python/bin/python3.12'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants