Skip to content

[python-package] prevent build-python.sh from modifying already-installed dependencies#6403

Merged
jameslamb merged 2 commits intomasterfrom
python-install-script
Apr 20, 2024
Merged

[python-package] prevent build-python.sh from modifying already-installed dependencies#6403
jameslamb merged 2 commits intomasterfrom
python-install-script

Conversation

@jameslamb
Copy link
Collaborator

The recommended workflow for building the Python package from source here uses the build-python.sh script, like this:

cmake -B build -S .
cmake --build build --target _lightgbm -j4
sh ./build-python.sh install --precompile

The version for the library from any two unreleased commits is the same (e.g. 4.3.0.99). To ensure that pip does not give up on successive runs and say "oh lightgbm==4.3.0.99 is already installed, I'm not installing this wheel", in #5907 we added --force-reinstall to the pip install dist/* in build-python.sh.

That has the unfortunate side-effect of also force-reinstalling all of lightgbm's strong runtime dependencies (numpy and scipy). That's undesirable for 2 reasons:

  • it's surprising to get your environment's numpy version upgraded by installing lightgbm, even when lightgbm is compatible with the version of numpy you already have
  • in a conda environment, this can result in a numpy conda package being replaced by a numpy wheel, which can cause a variety of linking and loading problems

This PR proposes avoiding that, by instead having build-python.sh install run pip uninstall --yes lightgbm.

How I tested this

In a conda environment without lightgbm installed, but with scipy and numpy installed, ran the following.

cmake -B build -S .
cmake --build build --target _lightgbm -j4
sh ./build-python.sh install --precompile

Saw this in the logs, confirming that it didn't change my numpy or scipy versions.

Requirement already satisfied: numpy in /Users/jlamb/miniforge3/envs/lgb-dev/lib/python3.11/site-packages (from lightgbm) (1.26.4)
Requirement already satisfied: scipy in /Users/jlamb/miniforge3/envs/lgb-dev/lib/python3.11/site-packages (from lightgbm) (1.12.0)

@jameslamb jameslamb merged commit f6ecd4d into master Apr 20, 2024
@jameslamb jameslamb deleted the python-install-script branch April 20, 2024 02:48
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants