You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu16.04+Python3.5安装GPU版XGBoost遇兼容及运行错误

Hey there, I’ve dealt with similar headaches installing GPU-enabled XGBoost on older Ubuntu/Python setups before—let’s walk through fixing each of your issues step by step.

1. Fixing Python 2 Syntax Errors During Package Installation

The SyntaxError from rabit’s Python files happens because older versions of the rabit submodule (or even some recent XGBoost branches) still have Python 2-style print statements (without parentheses) that break Python 3. Here’s how to fix it:

  • Switch to a stable, Python 3.5-compatible branch: The default main branch might have code that’s too new or not fully backported for Python 3.5. Try checking out a known compatible version like v1.0.2, which supports GPU and plays nice with Python 3.5:
    cd xgboost
    git checkout v1.0.2
    git submodule update --init --recursive  # Make sure rabit gets updated to the compatible version
    
  • Recompile and reinstall cleanly: First wipe old build artifacts, then redo the GPU build and Python installation:
    make clean
    rm -rf build
    mkdir -p build && cd build
    cmake .. -DUSE_CUDA=ON
    make -j$(nproc)
    cd ../python-package
    python3 setup.py install --user  # Using --user avoids sudo conflicts with system Python
    
  • Alternative manual fix (if switching branches isn’t an option): Find all .py files under xgboost/rabit/python/ and replace every instance of print "some text" with print("some text"). This is tedious but works if you need a specific branch.
2. Resolving Benchmark Test Errors

Let’s tackle each of your test issues one by one:

a. Missing dtest.dm file

This is almost always a path or missing test data issue:

  • Run benchmarks from the root XGBoost directory, not the python-package folder. The test scripts expect to find data files in the root’s data directories.
  • If you haven’t already, download the official test data using the provided script:
    cd xgboost
    ./dmlc-core/scripts/get_data.sh
    

b. DMatrix has no handle attribute / nthread parameter error

These issues stem from a mismatch between the compiled GPU backend and the Python API (either the package didn’t install correctly, or version mismatches):

  • Uninstall and reinstall cleanly: First remove any existing XGBoost installations:
    pip3 uninstall xgboost -y
    
    Then repeat the GPU build and installation steps above (making sure you’re in the correct branch).
  • Check parameter compatibility: For older XGBoost versions (like v1.0.2), the correct parameter for thread count is nthread, not n_jobs (which is used in newer versions). If your benchmark script uses n_jobs, switch it to nthread to match your installed version.
  • Verify GPU support: After installation, run this in a Python 3 shell to confirm everything’s working:
    import xgboost as xgb
    print(f"XGBoost version: {xgb.__version__}")
    print(f"CUDA enabled: {xgb.config.get_config()['USE_CUDA']}")
    
    You should see USE_CUDA: 1 if GPU support is correctly installed.
Quick Extra Tips
  • Use a virtual environment to isolate your XGBoost setup from system Python dependencies. For Python 3.5, you can set one up with:
    virtualenv -p python3.5 xgboost_env
    source xgboost_env/bin/activate
    
    Then run all your build and install commands inside this environment.
  • Double-check your CUDA version: XGBoost v1.0.2 requires CUDA 9.0 or newer. Ubuntu 16.04 works well with CUDA 9.1 or 10.0—make sure your installed CUDA version matches what XGBoost expects.

内容的提问来源于stack exchange,提问作者Jack Power

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:22:54