问题
I am trying to use XGBoost on Sagemaker notebook.
I am using conda_python3
kernel, and the following packages are installed:
- py-xgboost-mutex
- libxgboost
- py-xgboost
- py-xgboost-gpu
But once I am trying to import xgboost it fails on import:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-5943d1bfe3f1> in <module>()
----> 1 import xgboost as xgb
ModuleNotFoundError: No module named 'xgboost'
回答1:
In Sagemaker notebooks use the below steps
a) If in Notebook
i) !type python3
ii) Say the above is /home/ec2-user/anaconda3/envs/python3/bin/python3 for you
iii) !/home/ec2-user/anaconda3/envs/python3/bin/python3 -m pip install xgboost
iv) import xgboost
b) If using Terminal
i) conda activate conda_python3
ii) pip install xgboost
Disclaimer : sometimes the installation would fail with gcc version ,in that case update pip version before running install
回答2:
try reinstalling
pip uninstall xgboost
pip install xgboost
来源:https://stackoverflow.com/questions/62313532/xgboost-on-sagemaker-notebook-import-fails