Ubuntu 16系统已存在Python.h却无法定位,编译Pycaffe遇阻求助
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 yourMakefile.configand 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/libMake sure the paths match your actual Anaconda installation location (use
echo $CONDA_PREFIXto get the exact path if you’re unsure).Ensure Anaconda has priority in your PATH
Sometimes.bashrcentries get overridden by later system path exports. Runecho $PATHin your terminal—your Anacondabindirectory 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 ~/.bashrcto 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 systempython3.6-devpackage 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-devFor extra compatibility, consider using Anaconda’s gcc toolchain to avoid linker issues:
conda install -c conda-forge gcc_linux-64Wipe old build cache and rebuild from scratch
Stale build artifacts can cause weird path issues. Clean everything first:make clean make distcleanThen reconfigure your
Makefile.configand run:make all -j$(nproc) && make pycaffe
内容的提问来源于stack exchange,提问作者J. Devez

