From a4840b0268653bdb3361471202764fd174c6d2f9 Mon Sep 17 00:00:00 2001 From: phunterlau Date: Mon, 7 Dec 2015 22:29:46 -0800 Subject: [PATCH] update pip building, troubleshooting with new makefile, plus friendly error message when fail importing sklearn --- Makefile | 4 +--- python-package/build_trouble_shooting.md | 7 +++++-- python-package/conv_rst.py | 8 -------- python-package/setup_pip.py | 2 +- python-package/xgboost/__init__.py | 7 +++++-- 5 files changed, 12 insertions(+), 16 deletions(-) delete mode 100644 python-package/conv_rst.py diff --git a/Makefile b/Makefile index 54aeea9a6..986c5d774 100644 --- a/Makefile +++ b/Makefile @@ -177,11 +177,9 @@ Rcheck: R CMD check --as-cran xgboost*.tar.gz pythonpack: - #make clean + #for pip maintainer only cd subtree/rabit;make clean;cd .. rm -rf xgboost-deploy xgboost*.tar.gz - #pip install pypandoc and also brew/apt-get install pandoc - python python-package/conv_rst.py cp -r python-package xgboost-deploy #cp *.md xgboost-deploy/ cp LICENSE xgboost-deploy/ diff --git a/python-package/build_trouble_shooting.md b/python-package/build_trouble_shooting.md index c62846a83..67bcfda8c 100644 --- a/python-package/build_trouble_shooting.md +++ b/python-package/build_trouble_shooting.md @@ -18,9 +18,12 @@ Linux platform (also Mac OS X in general) **Solution 0**: Please check if you have: -* installed C++ compilers, for example `g++` and `gcc` (Linux) or `clang LLVM` (Mac OS X). Recommended compilers are `g++-5` or newer (Linux and Mac), or `clang` comes with Xcode in Mac OS X. For installting compilers, please refer to your system package management commands, e.g. `apt-get` `yum` or `brew`(Mac). +* installed the latest C++ compilers and `make`, for example `g++` and `gcc` (Linux) or `clang LLVM` (Mac OS X). Recommended compilers are `g++-5` or newer (Linux and Mac), or `clang` comes with Xcode in Mac OS X. For installting compilers, please refer to your system package management commands, e.g. `apt-get` `yum` or `brew`(Mac). * compilers in your `$PATH`. Try typing `gcc` and see if your have it in your path. * Do you use other shells than `bash` and install from `pip`? In some old version of pip installation, the shell script used `pushd` for changing directory and triggering the build process, which may failed some shells without `pushd` command. Please update to the latest version by removing the old installation and redo `pip install xgboost` +* Some outdated `make` may not recognize the recent changes in the `Makefile` and gives this error, please update to the latest `make`: + + `/usr/lib/ruby/gems/1.8/gems/make-0.3.1/bin/make:4: undefined local variable or method 'make' for main:Object (NameError)` **Trouble 1**: I see the same error message in **Trouble 0** when install from `pip install xgboost`. @@ -30,7 +33,7 @@ Linux platform (also Mac OS X in general) OSError: /home/dmlc/anaconda/lib/python2.7/site-packages/xgboost/./wrapper/libxgboostwrapper.so: invalid ELF header -**Solution 2**: Solution is as in 0 and 1 by installing `g++` compiler. The reason for this rare error is that, `pip` ships with a pre-compiled `libxgboostwrapper.so` with Mac for placeholder for allowing `setup.py` to find the right lib path. If a system doesn't compile, it may refer to this placeholder lib and fail. This placeholder `libxgboostwrapper.so` will be automatically removed and correctly generated by the compiling on-the-fly for the system. +**Solution 2**: Solution is as in 0 and 1 by installing the latest `g++` compiler and the latest `make`. The reason for this rare error is that, `pip` ships with a pre-compiled `libxgboostwrapper.so` with Mac for placeholder for allowing `setup.py` to find the right lib path. If a system doesn't compile, it may refer to this placeholder lib and fail. This placeholder `libxgboostwrapper.so` will be automatically removed and correctly generated by the compiling on-the-fly for the system. **Trouble 3**: My system's `pip` says it can't find a valid `xgboost` installation release on `PyPI`. **Solution 3**: Some linux system comes with an old `pip` version. Please update to the latest `pip` by following the official installation document at diff --git a/python-package/conv_rst.py b/python-package/conv_rst.py deleted file mode 100644 index 0ae956d33..000000000 --- a/python-package/conv_rst.py +++ /dev/null @@ -1,8 +0,0 @@ -# pylint: disable=invalid-name, exec-used -"""Convert README.md to README.rst for PyPI""" - -from pypandoc import convert - -read_md = convert('python-package/README.md', 'rst') -with open('python-package/README.rst', 'w') as rst_file: - rst_file.write(read_md) diff --git a/python-package/setup_pip.py b/python-package/setup_pip.py index b9b58ac8d..cdadef876 100644 --- a/python-package/setup_pip.py +++ b/python-package/setup_pip.py @@ -34,7 +34,7 @@ LIB_PATH = libpath['find_lib_path']() #and be sure to test it firstly using "python setup.py register sdist upload -r pypitest" setup(name='xgboost', #version=open(os.path.join(CURRENT_DIR, 'xgboost/VERSION')).read().strip(), - version='0.4a28', + version='0.4a30', description=open(os.path.join(CURRENT_DIR, 'README.rst')).read(), install_requires=[ 'numpy', diff --git a/python-package/xgboost/__init__.py b/python-package/xgboost/__init__.py index 06892851f..cd50ca6cc 100644 --- a/python-package/xgboost/__init__.py +++ b/python-package/xgboost/__init__.py @@ -10,8 +10,11 @@ import os from .core import DMatrix, Booster from .training import train, cv -from .sklearn import XGBModel, XGBClassifier, XGBRegressor -from .plotting import plot_importance, plot_tree, to_graphviz +try: + from .sklearn import XGBModel, XGBClassifier, XGBRegressor + from .plotting import plot_importance, plot_tree, to_graphviz +except ImportError: + print('Error when loading sklearn/plotting. Please install scikit-learn') VERSION_FILE = os.path.join(os.path.dirname(__file__), 'VERSION') __version__ = open(VERSION_FILE).read().strip()