2019년 1월 20일 일요일

Install xgboost in python (파이썬에서 xgboost 설치기)


설치전 끝까지 읽어보시기 바랍니다.

아래 글을 보고
https://xgboost.readthedocs.io/en/latest/build.html

환경 : python 3.6.4, 32 bit 환경, windows 에서 설치 시작해 보았습니다.

(py364_env) E:\Program Files (x86)\Python36-32>pip3 install xgboost
Collecting xgboost
  Downloading https://files.pythonhosted.org/packages/4f/4c/4969b10939c4557ae46e5569d07c0c7ce772b3d6b9c1401a6ed07059fdee/xgboost-0.81.tar.gz (636kB)
    100% |████████████████████████████████| 645kB 5.1MB/s
Files/directories not found in C:\Users\xxx\AppData\Local\Temp\pip-install-1eb0m6cr\xgboost\pip-egg-info

뭔가 이상한 오류가 발생합니다.

그래서 검색해보니 환경마다 다른 특정 파일을 다운로드 필요하다고 합니다.

좋은글을 발견



1. 다음 링크에서 적당한 파일 다운로드


https://www.lfd.uci.edu/~gohlke/pythonlibs/
(3.6버전에 32bit 환경이라 다음 파일 다운로드)
xgboost‑0.81‑cp36‑cp36m‑win32.whl

2. 다음 명령으로 설치

pip install [whl파일명]

(py364_env) E:\Program Files (x86)\Python36-32>pip install C:\Users\darts\Downloads\xgboost-0.81-cp36-cp36m-win32.whl
Processing c:\users\darts\downloads\xgboost-0.81-cp36-cp36m-win32.whl
Requirement already satisfied: numpy in e:\program files (x86)\python36-32\py364_env\lib\site-packages (from xgboost==0.81) (1.16.0)
Collecting scipy (from xgboost==0.81)
  Downloading https://files.pythonhosted.org/packages/18/d1/9ed926284d97c12cc4c07b81abce886dd4430c52b8323defc365ed04026e/scipy-1.2.0-cp36-cp36m-win32.whl (26.9MB)
    100% |████████████████████████████████| 27.0MB 734kB/s
Installing collected packages: scipy, xgboost
Successfully installed scipy-1.2.0 xgboost-0.81

(numpy가 구버전이라 설치가 안되면 numpy업그레이드 필요)

(py364_env) E:\Program Files (x86)\Python36-32>pip install numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/6e/ef/1402e6016ba0aa19463198be521b265c6bbe4ee892a7f42385d29e8d894d/numpy-1.16.0-cp36-cp36m-win32.whl (10.0MB)
    100% |████████████████████████████████| 10.0MB 1.9MB/s
Installing collected packages: numpy
Successfully installed numpy-1.16.0

4. 동작확인

설치는 된것 같은데 동작이 제대로 안됩니다.
(py364_env) E:\Program Files (x86)\Python36-32\py364_env\Scripts>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "E:\Program Files (x86)\Python36-32\py364_env\lib\site-packages\xgboost\__init__.py", line 11, in <module>
    from .core import DMatrix, Booster
  File "E:\Program Files (x86)\Python36-32\py364_env\lib\site-packages\xgboost\core.py", line 150, in <module>
    _LIB = _load_lib()
  File "E:\Program Files (x86)\Python36-32\py364_env\lib\site-packages\xgboost\core.py", line 141, in _load_lib
    'Error message(s): {}\n'.format(os_error_list))
xgboost.core.XGBoostError: XGBoost Library (xgboost.dll) could not be loaded.
Likely causes:
  * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windows, libgomp.so for UNIX-like OSes)
  * You are running 32-bit Python on a 64-bit OS
Error message(s): ['[WinError 126] 지정된 모듈을 찾을 수 없습니다']

구글링
2018. 9. 28. - Exception has occurred: xgboost.core.XGBoostError XGBoost Library (xgboost.dll)could not be loadedLikely causes: * OpenMP runtime is not installed (vcomp140.dll or libgomp-1.dll for Windowslibgomp.so for UNIX-like OSes) * You are running 32-bit Python on a 64-bit OSError message(s): ['[WinError ...


5. 다시 원점으로

64 bit windows에서는 64 bit Python을 설치하여야 한다고 하네요

이번엔 anaconda 환경에서 설치 64 bit anaconda python 3.7 버전으로 시도

6. 다운로드

https://www.lfd.uci.edu/~gohlke/pythonlibs/ 여기에서 아래 파일 다운로드
xgboost-0.81-cp37-cp37m-win_amd64.whl

7. pip install

(base) C:\Users\xxx>python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z


(base) C:\Users\xxx>pip install C:\Users\darts\Downloads\xgboost-0.81-cp37-cp37m-win_amd64.whl
Processing c:\users\darts\downloads\xgboost-0.81-cp37-cp37m-win_amd64.whl
Requirement already satisfied: numpy in e:\programdata\anaconda3\lib\site-packages (from xgboost==0.81) (1.15.4)
Requirement already satisfied: scipy in e:\programdata\anaconda3\lib\site-packages (from xgboost==0.81) (1.1.0)
Installing collected packages: xgboost
Successfully installed xgboost-0.81


8. 제대로 설치되었는지 확인

(base) C:\Users\xxx>python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
>>>

9. 결론

- 64 bit 윈도우에서는 64bit용 python 설치 필요
https://www.lfd.uci.edu/~gohlke/pythonlibs/ 여기에서 운영체제와 python 버전이 맞는 파일을 다운로드
- pip install whl파일

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

10. 시간이 흘러 2020.08.23일

Python 3.6 64bit windows환경 에서 간단하게 pip로 간단하게 설치 가능합니다.

C:\Users\USER\Documents\python\stock>pip3 install xgboost
Collecting xgboost
  Downloading https://files.pythonhosted.org/packages/b8/1c/8384c92f40e9a4739d0b474573d9bfd19b7846b5d28f6c53294e2c5c5af4/xgboost-1.2.0-py3-none-win_amd64.whl (86.5MB)
     |████████████████████████████████| 86.5MB 218kB/s
Collecting scipy (from xgboost)
  Downloading https://files.pythonhosted.org/packages/9e/66/57d6cfa52dacd9a57d0289f8b8a614b2b4f9c401c2ac154d6b31ed8257d6/scipy-1.5.2-cp38-cp38-win_amd64.whl (31.4MB)
     |████████████████████████████████| 31.4MB 595kB/s
Collecting numpy (from xgboost)
  Downloading https://files.pythonhosted.org/packages/c7/7d/ea9e28c3a99f50e77ee9a0e3759adb6537b2bb7a84aef27b8c0ddc431b48/numpy-1.19.1-cp38-cp38-win_amd64.whl (13.0MB)
     |████████████████████████████████| 13.0MB 3.3MB/s
Installing collected packages: numpy, scipy, xgboost
Successfully installed numpy-1.19.1 scipy-1.5.2 xgboost-1.2.0
WARNING: You are using pip version 19.2.3, however version 20.2.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\USER\Documents\python\stock>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xgboost
>>>


댓글 없음:

댓글 쓰기