如何在Python中快速安装机器学习包:LGB、XGB、CatBoost

2022-06-16 18:13:31 浏览数 (2)

问题:有时大家在安装上面几个机器学习的包时,会出现如下类似的错误

代码语言:javascript复制
(oldgeek) C:Usersoldgeek>pip install lightgbm
Collecting lightgbm
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/ba/24/2f83a1008c8add8cd9da03163f911be6b555eb2b9166b5ab74e1ad63ff40/lightgbm-3.3.2-py3-none-win_amd64.whl
ERROR: Operation cancelled by user

原因

大家看错误提示就知道了,都是timeout惹的祸。

解决办法

  • 尝试换成国内源

参考安装脚本

安装LGB

代码语言:javascript复制
pip install lightgbm -i https://pypi.tuna.tsinghua.edu.cn/simple

执行结果

代码语言:javascript复制
(oldgeek) C:Usersoldgeek>pip install lightgbm -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting lightgbm
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ba/24/2f83a1008c8add8cd9da03163f911be6b555eb2b9166b5ab74e1ad63ff40/lightgbm-3.3.2-py3-none-win_amd64.whl (1.0 MB)
     |████████████████████████████████| 1.0 MB 6.4 MB/s
Requirement already satisfied: scipy in d:toolsminiconda3envsoldgeeklibsite-packages (from lightgbm) (1.7.3)
Requirement already satisfied: scikit-learn!=0.22.0 in d:toolsminiconda3envsoldgeeklibsite-packages (from lightgbm) (1.0.2)
Requirement already satisfied: wheel in d:toolsminiconda3envsoldgeeklibsite-packages (from lightgbm) (0.37.1)
Requirement already satisfied: numpy in d:toolsminiconda3envsoldgeeklibsite-packages (from lightgbm) (1.22.3)
Requirement already satisfied: threadpoolctl>=2.0.0 in d:toolsminiconda3envsoldgeeklibsite-packages (from scikit-learn!=0.22.0->lightgbm) (2.2.0)
Requirement already satisfied: joblib>=0.11 in d:toolsminiconda3envsoldgeeklibsite-packages (from scikit-learn!=0.22.0->lightgbm) (1.1.0)
Installing collected packages: lightgbm
Successfully installed lightgbm-3.3.2

安装XGB

代码语言:javascript复制
pip install xgboost -i https://pypi.tuna.tsinghua.edu.cn/simple

安装CatBoost

代码语言:javascript复制
pip install catboost -i https://pypi.tuna.tsinghua.edu.cn/simple

安装库包出现超时一般都是访问源太慢,可考虑换成国内的镜像源去解决

0 人点赞