Merge pull request #230 from jseabold/python-install

Make the Python wrappers installable without path munging
This commit is contained in:
Tianqi Chen 2015-04-08 15:02:37 -07:00
commit 23c273173f
19 changed files with 64 additions and 69 deletions

View File

@ -1,5 +1,4 @@
#!/usr/bin/python #!/usr/bin/python
import sys
def loadfmap( fname ): def loadfmap( fname ):
fmap = {} fmap = {}

View File

@ -1,10 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import sys
import numpy as np import numpy as np
import scipy.sparse import scipy.sparse
# append the path to xgboost, you may need to change the following line
# alternatively, you can add the path to PYTHONPATH environment variable
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
### simple example ### simple example

View File

@ -1,7 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import sys
import numpy as np import numpy as np
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
dtrain = xgb.DMatrix('../data/agaricus.txt.train') dtrain = xgb.DMatrix('../data/agaricus.txt.train')

View File

@ -1,7 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import sys
import numpy as np import numpy as np
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
### load data in do training ### load data in do training

View File

@ -1,7 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import sys
import numpy as np import numpy as np
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
### ###
# advanced: cutomsized loss function # advanced: cutomsized loss function

View File

@ -1,6 +1,4 @@
#!/usr/bin/python #!/usr/bin/python
import sys
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
## ##
# this script demonstrate how to fit generalized linear model in xgboost # this script demonstrate how to fit generalized linear model in xgboost

View File

@ -1,7 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import sys
import numpy as np import numpy as np
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
### load data in do training ### load data in do training

View File

@ -1,7 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import sys
import numpy as np import numpy as np
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
### load data in do training ### load data in do training

View File

@ -4,8 +4,6 @@ Created on 1 Apr 2015
@author: Jamie Hall @author: Jamie Hall
''' '''
import sys
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
import numpy as np import numpy as np

View File

@ -1,7 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import sys
import numpy as np import numpy as np
sys.path.append('../../wrapper')
import xgboost as xgb import xgboost as xgb
### load data in do training ### load data in do training

View File

@ -1,14 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# this is the example script to use xgboost to train # this is the example script to use xgboost to train
import inspect
import os
import sys
import numpy as np import numpy as np
# add path of xgboost python module
code_path = os.path.join(
os.path.split(inspect.getfile(inspect.currentframe()))[0], "../../wrapper")
sys.path.append(code_path)
import xgboost as xgb import xgboost as xgb

View File

@ -1,9 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# make prediction # make prediction
import sys
import numpy as np import numpy as np
# add path of xgboost python module
sys.path.append('../../wrapper/')
import xgboost as xgb import xgboost as xgb
# path to where the data lies # path to where the data lies

View File

@ -1,9 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# this is the example script to use xgboost to train # this is the example script to use xgboost to train
import sys
import numpy as np import numpy as np
# add path of xgboost python module
sys.path.append('../../wrapper/')
import xgboost as xgb import xgboost as xgb
from sklearn.ensemble import GradientBoostingClassifier from sklearn.ensemble import GradientBoostingClassifier
import time import time

View File

@ -1,7 +1,5 @@
#! /usr/bin/python #! /usr/bin/python
import sys
import numpy as np import numpy as np
sys.path.append('../../wrapper/')
import xgboost as xgb import xgboost as xgb
# label need to be 0 to num_class -1 # label need to be 0 to num_class -1

View File

@ -1,5 +1,4 @@
#!/usr/bin/python #!/usr/bin/python
import sys
fo = open( 'machine.txt', 'w' ) fo = open( 'machine.txt', 'w' )
cnt = 6 cnt = 6

View File

@ -10,13 +10,17 @@ This should give you xgboost.exe for CLI version and xgboost_wrapper.dll for pyt
Use Python Module Use Python Module
===== =====
* After you build the dll, you can simply add the path to [../wrapper](../wrapper) to sys.path and import xgboost * After you build the dll, you can install the Python package from the [../wrapper](../wrapper) folder
```
python setup.py install
```
And import it as usual
``` ```
sys.path.append('path/to/xgboost/wrapper')
import xgboost as xgb import xgboost as xgb
``` ```
* Alternatively, you can add that path to system enviroment variable ```PYTHONPATH```
- Doing so allows you to import xgboost directly like other python packages
R Package R Package
==== ====

View File

@ -5,6 +5,7 @@ This folder provides wrapper of xgboost to other languages
Python Python
===== =====
* To make the python module, type ```make``` in the root directory of project * To make the python module, type ```make``` in the root directory of project
* Install with `python setup.py install` from this directory.
* Refer also to the walk through example in [demo folder](../demo/guide-python) * Refer also to the walk through example in [demo folder](../demo/guide-python)
R R

0
wrapper/__init__.py Normal file
View File

28
wrapper/setup.py Normal file
View File

@ -0,0 +1,28 @@
import os
from setuptools import setup
class XGBoostLibraryNotFound(Exception):
pass
cur_dir = os.path.dirname(os.path.abspath(__file__))
if os.name == 'nt':
dll_path = os.path.join(cur_dir,
'../windows/x64/Release/xgboost_wrapper.dll')
else:
dll_path = os.path.join(cur_dir, 'libxgboostwrapper.so')
if not os.path.exists(dll_path):
raise XGBoostLibraryNotFound("XGBoost library not found. Did you run "
"../make?")
setup(name="xgboost",
version="0.32",
description="Python wrappers for XGBoost: eXtreme Gradient Boosting",
zip_safe=False,
py_modules=['xgboost'],
data_files=[dll_path],
url="https://github.com/dmlc/xgboost")