本文共 1144 字,大约阅读时间需要 3 分钟。
原因:swig C++ 代码转 python
运行命令:
gcc -c -fpic example.c example_wrap.c -I/usr/local/include/python2.0
报错如下:
example_wrap.c:154:21: fatal error: Python.h: No such file or directorycompilation terminated.
(方法一)找到 系统 python 下的 Python.h
# 去系统下发现可用 Pythoncd /usr/include/find | grep python# 可以发现这里有 python2.7 和 python3.5drwxr-xr-x 2 root root 12288 Aug 10 2018 python2.7/lrwxrwxrwx 1 root root 10 Nov 29 2017 python3.5 -> python3.5m/drwxr-xr-x 2 root root 4096 Feb 2 2018 python3.5m/cd /usr/include/python3.5# 就可以发现 Python.h 文件find | grep Python.h# 输出如下./Python.h
gcc -c -fpic example.c example_wrap.c -I/usr/include/python3.5
便可以顺利完成转化了(该任务可能和您的不一样呢);
(方法二)到 Anaconda3 目录下 寻找含有 Python.h 的 环境
cd /home/moli/anaconda3~/anaconda3$ find | grep Python.h./envs/torch11/include/python3.7m/Python.h./envs/nice/include/python3.6m/Python.h./envs/n2n366/include/python3.6m/Python.h./envs/pix2pix/include/python3.6m/Python.h./envs/tf20/include/python3.6m/Python.h./include/python3.6m/Python.h
gcc -c -fpic example.c example_wrap.c -I/home/moli/anaconda3/include/python3.6m
转载地址:http://fcmxf.baihongyu.com/