如何卸载从源码安装的Python版XGBoost?pip卸载失败求助
Hey there, let's sort out this XGBoost uninstall problem you're hitting! Since you installed XGBoost from source code instead of using pip, pip doesn't track that installation—this is exactly why you're seeing the "Cannot uninstall requirement xgboost, not installed" error. Here's a step-by-step fix:
Step 1: Locate your XGBoost installation folder
Open a Python shell and run these lines to find where XGBoost is installed:import xgboost print(xgboost.__file__)This will output a path like
/usr/local/lib/python3.9/site-packages/xgboost/__init__.py. The folder you need to delete is the parent directory of this file—so in this example, it's/usr/local/lib/python3.9/site-packages/xgboost/.Step 2: Manually delete the XGBoost folder
- For Linux/macOS, use this terminal command (replace the path with your actual folder location):
rm -rf /path/to/your/xgboost/folder - For Windows, you can either navigate to the folder in File Explorer and delete it, or run this Command Prompt command:
rmdir /s /q C:\path\to\your\xgboost\folder
- For Linux/macOS, use this terminal command (replace the path with your actual folder location):
Step 3: Verify the uninstall
Open a new Python shell and try runningimport xgboost. If you get aModuleNotFoundError, that means the old installation is gone for good.Step 4: Install the updated XGBoost
Now you're ready to install the latest version. You can either:- Compile it from the updated source code following the same steps you used before, or
- Use
pipto install the latest stable release:pip install --upgrade xgboost
A quick note: If your original source compilation installed system-level libraries (rare for most Python setups), you can navigate back to the folder where you compiled XGBoost and run make uninstall if the project's Makefile supports it. But for most cases, deleting the site-packages folder is sufficient.
内容的提问来源于stack exchange,提问作者Silburt

