Skip to content

Commit 00d3731

Browse files
authored
Merge pull request #721 from Ana06/fix-pyinstaller
[CI] vboxcommon: Clean environment for subprocess
2 parents 0e97bd7 + ba2523a commit 00d3731

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

.github/workflows/build-vbox.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Checkout code
2121
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2222
- name: Install build requirements
23-
run: python -m pip install --upgrade pip setuptools pyinstaller pgi
23+
run: python -m pip install --upgrade pip pyinstaller
2424
- name: Build standalone executables
2525
run: |
2626
cd virtualbox

virtualbox/vboxcommon.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,23 @@ def __run_vboxmanage(cmd, real_time=False):
4949
cmd: list with the command and its arguments
5050
real_time: Boolean that determines if displaying the output in realtime or returning it.
5151
"""
52+
# When running as a PyInstaller bundle, LD_LIBRARY_PATH is set,
53+
# which can cause conflicts with external binaries like VBoxManage.
54+
# We create a clean environment for the subprocess to use the system's libraries.
55+
env = os.environ.copy()
56+
if sys.frozen and "LD_LIBRARY_PATH" in env:
57+
# 'sys.frozen' is True when running from a PyInstaller executable.
58+
# We can either remove the variable or, more safely, restore the original
59+
# one if PyInstaller saved it. PyInstaller often saves it as LD_LIBRARY_PATH_ORIG.
60+
if "LD_LIBRARY_PATH_ORIG" in env:
61+
env["LD_LIBRARY_PATH"] = env["LD_LIBRARY_PATH_ORIG"]
62+
else:
63+
del env["LD_LIBRARY_PATH"]
64+
5265
if real_time:
53-
return subprocess.run(cmd, stderr=sys.stderr, stdout=sys.stdout)
66+
return subprocess.run(cmd, stderr=sys.stderr, stdout=sys.stdout, env=env)
5467
else:
55-
return subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
68+
return subprocess.run(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
5669

5770

5871
def run_vboxmanage(cmd, real_time=False):

0 commit comments

Comments
 (0)