「已解决」Python.h file not found on Ubuntu 20.04

在Ubuntu20.04上配置OpenCV4时遇到编译错误,提示找不到Python.h。通过`locatePython.h`命令找到了多个Python头文件的位置,选择了/usr/include/python3.10/Python.h,并更新了CPATH和LD_LIBRARY_PATH环境变量来解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ubuntu20.04配置opencv4时出现报错:

fatal error: Python.h: No such file or directory
   17 | #include <Python.h>
      |          ^~~~~~~~~~
compilation terminated.

解决方案

  1. 找到Python.h位置
locate Python.h

结果:

/home/cedric/anaconda3/envs/csgo_env/include/python3.6m/Python.h
/home/cedric/anaconda3/envs/csgo_env/lib/python3.6/site-packages/tensorflow/include/external/local_config_python/python_include/Python.h
/home/cedric/anaconda3/envs/decdiff_env/include/python3.8/Python.h
/home/cedric/anaconda3/envs/diffuser_env/include/python3.8/Python.h
/home/cedric/anaconda3/envs/stable_diffusion_webui/include/python3.10/Python.h
/home/cedric/anaconda3/include/python3.9/Python.h
/home/cedric/anaconda3/pkgs/python-3.10.6-haa1d7c7_1/include/python3.10/Python.h
/home/cedric/anaconda3/pkgs/python-3.6.9-h265db76_0/include/python3.6m/Python.h
/home/cedric/anaconda3/pkgs/python-3.8.16-h7a1cb2a_2/include/python3.8/Python.h
/home/cedric/anaconda3/pkgs/python-3.9.13-haa1d7c7_1/include/python3.9/Python.h
/snap/jupyter/6/include/python3.7m/Python.h
/usr/include/python2.7/Python.h
/usr/include/python3.10/Python.h
  1. 使用/usr/include/python3.10/Python.h
export CPATH=/usr/include/python3.10:$CPATH
export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值