I have Python on my Ubuntu system, but gcc can't find Python.h

后端 未结 14 1734
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 13:10

I am on a school computer, so I can\'t install anything.

I am trying to create C code which can be run in Python. It seems all the articles I am finding on it requi

14条回答
  •  有刺的猬
    2020-11-27 13:32

    It happens because Python.h is not located in the default include folder (which is /usr/include/ ).

    Installing Python-dev might help:

    $ sudo apt-get install python-dev 
    

    But mostly the problem will persist because the development packages are made inside a separate folder inside the include folder itself ( /usr/include/python2.7 or python3).

    So you should either specify the library folder using -I option in gcc or by creating soft-links to everything inside those folders to just outside (I'd prefer the former option).

    Using -I option in gcc:

    $ gcc -o hello -I /usr/include/python2.7 helloworld.c
    

    Creating soft-links :

    $ sudo ln -sv /usr/include/python2.7/* /usr/include/
    

提交回复
热议问题