解决caffe中的python环境安装的问题

由于caffe(GitHub - BVLC/caffe: Caffe: a fast open framework for deep learning.)使用的python版本是2.7,而非python3,所以安装的时候使用命令:sudo apt install python2.7进行安装。

而在安装python的各种包时,也不能用命令"sudo pip install 包名"安装,这样只会为python3安装相应的包。而应该用"sudo python -m pip install 包名",以安装wheel为例,使用命令"sudo python -m pip install wheel"进行安装。

如果你的linux系统中未安装pip,会报错"/usr/bin/python: No module named pip",这是因为python2.7对应的pip版本有要求。如何为Python 2.7中安装pip,可以参考这个链接(Python 2.7中安装pip_python2.7安装pip_dongzi321的博客-CSDN博客

搞定pip的安装后,就可以进入到"/caffe/python"目录下,使用命令"sudo python -m pip install -r requirements.txt"安装一堆依赖包了。安装的过程中会遇到一个错误:提示找不到Python.h文件

复制代码
    configure: creating ./config.status
    config.status: creating _posixsubprocess_config.h
    building '_posixsubprocess32' extension
    creating build/temp.linux-x86_64-2.7
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-W1mjrO/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o
    _posixsubprocess.c:16:10: fatal error: Python.h: 没有那个文件或目录
       16 | #include "Python.h"
          |          ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-s937xK/subprocess32/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-PDa3Jr-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-s937xK/subprocess32/
You are using pip version 9.0.1, however version 23.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

这个问题是由于系统中未安装python2.7的开发包导致的,解决方法是使用命令"sudo apt install python2.7-dev"进行安装即可。

注意:不要按这种提示"You are using pip version 9.0.1, however version 23.2.1 is available.

You should consider upgrading via the 'pip install --upgrade pip' command."去升级pip,因为升级后就会与python2.7不匹配了。

相关推荐
绝世这天下10 分钟前
【在 DGX Spark 上运行 vLLM-Omni 用于 Qwen3-TTS(语音设计,语音克隆)】
人工智能
陈大鱼头1 小时前
[译]费尽心思来保障 OpenClaw ?那跟直接用 GPT 有什么区别?
人工智能
Fleshy数模1 小时前
玩转OpenCV:视频椒盐噪声处理与图像形态学操作实战
人工智能·opencv·音视频
程序媛一枚~1 小时前
✨✨✨使用Python,OpenCV及图片拼接生成❤️LOVE❤️字样图,每张小图加随机颜色边框,大图加随机大小随机颜色边框
图像处理·python·opencv·numpy·图像拼接
幂律智能1 小时前
Agent × 流程引擎融合架构:从静态流程到智能流程编排
人工智能·架构·agent
无垠的广袤1 小时前
ChatECNU 大语言模型与 PicoClaw 部署
人工智能·语言模型·自然语言处理·嵌入式·树莓派
MediaTea2 小时前
Python:collections.Counter 常用函数及应用
开发语言·python
爱淋雨的男人2 小时前
自动驾驶感知相关算法
人工智能·算法·自动驾驶
互联网科技看点2 小时前
AI算力爆发叠加数据资产风口,铂拉锐科技布局去中心化数字生态
人工智能·科技·去中心化
如若1232 小时前
flash-attn 安装失败?从报错到成功的完整排雷指南(CUDA 12.8 + PyTorch 2.7)
人工智能·pytorch·python