ubuntu20.04配置opencv4时出现报错:
fatal error: Python.h: No such file or directory
17 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
解决方案
- 找到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/p

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





