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

Ubuntu 16系统已存在Python.h却无法定位,编译Pycaffe遇阻求助

Fixing "Python.h not found" When Building Pycaffe with Anaconda 3.6

Hey, I’ve been in your shoes trying to get Pycaffe up and running with Anaconda, so let’s walk through some concrete steps to fix that stubborn Python.h error:

  • Verify your build config points to Anaconda, not system Python
    Even if your shell uses Anaconda Python, Caffe’s build scripts might still default to the system version. Open your Makefile.config and double-check these lines:

    # Comment out system Python paths if they exist
    # PYTHON_INCLUDE := /usr/include/python2.7 /usr/lib/python2.7/dist-packages/numpy/core/include
    
    # Replace with your Anaconda paths
    PYTHON_INCLUDE := $(HOME)/anaconda3/include/python3.6m \
                     $(HOME)/anaconda3/lib/python3.6/site-packages/numpy/core/include
    PYTHON_LIB := $(HOME)/anaconda3/lib
    

    Make sure the paths match your actual Anaconda installation location (use echo $CONDA_PREFIX to get the exact path if you’re unsure).

  • Ensure Anaconda has priority in your PATH
    Sometimes .bashrc entries get overridden by later system path exports. Run echo $PATH in your terminal—your Anaconda bin directory should be at the very start. If not, move this line to the end of your .bashrc:

    export PATH="$CONDA_PREFIX/bin:$PATH"
    

    Then run source ~/.bashrc to apply the change and verify again.

  • Force the compiler to use Anaconda’s Python headers
    If the build config still isn’t picking up the right path, pass the include directory directly to the compiler when building:

    make pycaffe CFLAGS="-I$CONDA_PREFIX/include/python3.6m"
    

    This bypasses any config mismatches and tells gcc exactly where to look for Python.h.

  • Install Anaconda’s own Python development tools
    The system python3.6-dev package might not play nicely with Anaconda’s isolated environment. Install Anaconda’s equivalent dev components instead:

    conda install python=3.6
    conda install -c anaconda python-dev
    

    For extra compatibility, consider using Anaconda’s gcc toolchain to avoid linker issues:

    conda install -c conda-forge gcc_linux-64
    
  • Wipe old build cache and rebuild from scratch
    Stale build artifacts can cause weird path issues. Clean everything first:

    make clean
    make distclean
    

    Then reconfigure your Makefile.config and run:

    make all -j$(nproc) && make pycaffe
    

内容的提问来源于stack exchange,提问作者J. Devez

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:46:39