Xgboost: import in python 2.7 fails with 127 error in Win 7

Created on 7 Mar 2016  Â·  3Comments  Â·  Source: dmlc/xgboost

Windows 7, R works fine
python 2.7.10 | EPD 7.5-3 (64-bit), numpy, scipy, theano etc works fine

Steps:

  • cloned repository recursively
  • build and make in the main directory (no visible errors, libxgboost.dll and libxgboost.a libraries are in /lib folder)
  • switch to python-package folder, call python setup.py install, again no visible errors
  • start python, call
    >>>import xgboost
    get the following error message:
  File "<stdin>", line 1, in <module>
  File "xgboost\__init__.py", line 11, in <module>
    from .core import DMatrix, Booster
  File "xgboost\core.py", line 83, in <module>
    _LIB = _load_lib()
  File "xgboost\core.py", line 77, in _load_lib
    lib = ctypes.cdll.LoadLibrary(lib_path[0])
  File "P:\Python\Python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "P:\Python\Python27\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 127] The specified procedure could not be found

I hacked core.py to check which library it actually tries to load :)
it actually looks for the right dll
/Sources/xgb/python-package/xgboost/../../lib/libxgboost.dll
which is exactly where it is located, freshly built few minutes ago

Most helpful comment

I had the same error, but the fix leaves many questions unanswered. I originally compiled with minGW using some clearer directions.

It turned out that, for whatever reason, having the mingw path at the _beginning_ of the system path (rather than end for me) solved the issue for that compilation.

>>> dir = r'C:\Program Files\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev1\mingw64\bin'
>>> import os
>>> os.environ['PATH'].count(dir) # Here I show its already in the path at least once
1
>>> os.environ['PATH'].find(dir) # We see its at the end of my path
1491
>>> os.environ['PATH'] = dir + ';' + os.environ['PATH'] # I put it on the beginning of the path, NOT THE END.
>>> import xgboost # I modified core.py to print the directory of the requested dll. It imports successfully.
C:\Users\Joey\Anaconda2\lib\site-packages\xgboost-0.6-py2.7.egg\xgboost\libxgboost.dll

This is the only way it worked

Please note that the directory of the requested dll is the same in both the failure and successful case, so it is not that. The only thing that changes is putting the mingw/bin directory in the beginning of the path variable. Therefore, I believe it might be an issue with minGW or how minGW and python were communicating (not an expert here).

The REAL fix was to compile using Visual Studio, by installing cmake (add to your path during install!), and following the visual studio directions (which really need to be elaborated, not everyone is a wiz at this stuff). So in total: Follow the directions using Git For Windows, clone the repository, install cmake and add 'cmake' to your path, follow the visual studio install directions to build using cmake and visual studio (install the latest visual studio community edition if you haven't already), now copy the only libxgboost.dll to your python-packages directory, open a command prompt, and now "python setup.py install" from python-packages.

Note for Visual Studio installs you do not need the system to know the path of minGW.

All 3 comments

  1. How do you build the xgboost?

    you should follow this:
    http://xgboost.readthedocs.io/en/latest/build.html#building-on-windows

  2. then install the python package

I had the exact same error with you.
Try to uninstall other version of Python on your machine and reboot. I know this is not a nice solution, but it works for me.

I had the same error, but the fix leaves many questions unanswered. I originally compiled with minGW using some clearer directions.

It turned out that, for whatever reason, having the mingw path at the _beginning_ of the system path (rather than end for me) solved the issue for that compilation.

>>> dir = r'C:\Program Files\mingw-w64\x86_64-6.2.0-posix-seh-rt_v5-rev1\mingw64\bin'
>>> import os
>>> os.environ['PATH'].count(dir) # Here I show its already in the path at least once
1
>>> os.environ['PATH'].find(dir) # We see its at the end of my path
1491
>>> os.environ['PATH'] = dir + ';' + os.environ['PATH'] # I put it on the beginning of the path, NOT THE END.
>>> import xgboost # I modified core.py to print the directory of the requested dll. It imports successfully.
C:\Users\Joey\Anaconda2\lib\site-packages\xgboost-0.6-py2.7.egg\xgboost\libxgboost.dll

This is the only way it worked

Please note that the directory of the requested dll is the same in both the failure and successful case, so it is not that. The only thing that changes is putting the mingw/bin directory in the beginning of the path variable. Therefore, I believe it might be an issue with minGW or how minGW and python were communicating (not an expert here).

The REAL fix was to compile using Visual Studio, by installing cmake (add to your path during install!), and following the visual studio directions (which really need to be elaborated, not everyone is a wiz at this stuff). So in total: Follow the directions using Git For Windows, clone the repository, install cmake and add 'cmake' to your path, follow the visual studio install directions to build using cmake and visual studio (install the latest visual studio community edition if you haven't already), now copy the only libxgboost.dll to your python-packages directory, open a command prompt, and now "python setup.py install" from python-packages.

Note for Visual Studio installs you do not need the system to know the path of minGW.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

colinsongf picture colinsongf  Â·  4Comments

tqchen picture tqchen  Â·  4Comments

FabHan picture FabHan  Â·  4Comments

ivannz picture ivannz  Â·  3Comments

uasthana15 picture uasthana15  Â·  4Comments