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

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

猜你喜欢

转载自blog.csdn.net/CCCDeric/article/details/129722580