Caffe框架与Nvidia DIGITS兼容Python3吗?编译版本识别异常求助
Hey there, let's work through your two key issues step by step—first resolving the Protobuf version clash, then getting CMake to properly target your Anaconda Python 3.6 environment instead of system Python 2.7.
1. Resolve Protobuf Version Conflict
Caffe (especially older official branches) typically relies on Protobuf 2.x versions, so having both 2.6.1 and 3.5 installed will cause conflicts. Here's how to clean this up:
- First, completely remove all Protobuf installations from your Anaconda environment:
# Activate your Anaconda env first conda activate your_env_name # Uninstall conda-managed protobuf conda uninstall protobuf # Uninstall any pip-managed protobuf (if present) pip uninstall protobuf - Install the compatible Protobuf version (2.6.1) that Caffe expects:
conda install protobuf=2.6.1 # Or use pip if conda doesn't have the version: pip install protobuf==2.6.1 - Verify the installation worked:
You should seepython -c "import google.protobuf; print(google.protobuf.__version__)"2.6.1printed—this confirms your environment now uses the correct Protobuf version.
2. Force CMake to Use Anaconda Python 3.6
CMake often defaults to system Python (2.7 in your case) unless explicitly told otherwise. Here's how to point it to your Anaconda environment:
- Activate your Anaconda Python 3.6 environment (if not already active):
conda activate your_env_name - Navigate to your Caffe
builddirectory, clear any old CMake cache (to avoid leftover configs):cd path/to/caffe/build rm -rf * - Run CMake with explicit Python path arguments (these commands dynamically pull paths from your active environment):
cmake .. \ -DPYTHON_EXECUTABLE=$(which python) \ -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ -DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sc; print(sc.get_config_var('LIBDIR') + '/libpython3.6m.so')")- Note: On macOS, the Python library filename might be
libpython3.6m.dylibinstead of.so—adjust the command if needed.
- Note: On macOS, the Python library filename might be
- After running CMake, check the output for lines like:
Found PythonInterp: /home/your_user/anaconda3/envs/your_env_name/bin/python (found suitable version "3.6.x", minimum required is "3.5")
This confirms CMake is now using your Anaconda Python 3.6 environment. - Proceed with compiling Caffe as usual:
make -j$(nproc) make pycaffe
Quick Additional Checks
- Make sure your Anaconda environment has all Caffe dependencies installed:
conda install numpy scipy boost-python opencv - If you're using a
Makefile.config(instead of pure CMake), double-check that thePYTHON_INCLUDEandPYTHON_LIBpaths point to your Anaconda environment, not system Python.
内容的提问来源于stack exchange,提问作者krishnab

