Skip to content

Fall back to cpu_count when psutil is unavailable at build time#419

Open
OuariachiRafik wants to merge 1 commit into
google-research:masterfrom
OuariachiRafik:fix/psutil-build-fallback
Open

Fall back to cpu_count when psutil is unavailable at build time#419
OuariachiRafik wants to merge 1 commit into
google-research:masterfrom
OuariachiRafik:fix/psutil-build-fallback

Conversation

@OuariachiRafik

Copy link
Copy Markdown

Problem

pip install gfootball can fail with:

ModuleNotFoundError: No module named 'psutil'
error: Google Research Football compilation failed

gfootball/build_game_engine.sh runs an inline Python snippet that imports
psutil to size compilation parallelism. psutil is a runtime dependency,
so it is not guaranteed to be present in the build environment — under
PEP 517 build isolation it is absent, and the build aborts before any C++
compilation. Reported in #414.

Fix

Wrap the psutil import in a try/except ImportError and fall back to
multiprocessing.cpu_count() when it is unavailable, with an outer shell
guard falling back to 1. This completes the existing
# TODO: Try importing psutil and if failed fall back to ... in the same file.
Behavior is unchanged when psutil is present.

Testing

Reproduced #414 in a clean environment without psutil in the build environment.
Before: the build failed at running build_ext with the psutil error.
After: the build proceeds past the parallelism step into the C++/cmake stage
(the psutil error no longer occurs).

Fixes #414.

build_game_engine.sh imports psutil to decide compilation parallelism, but
psutil is not guaranteed to be present in the build environment (e.g. under
PEP 517 build isolation), causing 'ModuleNotFoundError: No module named
psutil' and aborting the build before compilation. Wrap the import in a
try/except that falls back to multiprocessing.cpu_count(), completing the
existing TODO. Fixes google-research#414.

Signed-off-by: Hammadi Rafik Ouariachi <hrafik1122@gmail.com>
@google-cla

google-cla Bot commented Jul 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@OuariachiRafik

OuariachiRafik commented Jul 4, 2026

Copy link
Copy Markdown
Author

@googlebot I signed the CLA !

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.

Failed building wheel for gfootball

1 participant