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

后端 未结 14 1782
爱一瞬间的悲伤
爱一瞬间的悲伤 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:30

    On Ubuntu, you would need to install a package called python-dev. Since this package doesn't seem to be installed (locate Python.h didn't find anything) and you can't install it system-wide yourself, we need a different solution.

    You can install Python in your home directory -- you don't need any special permissions to do this. If you are allowed to use a web browser and run a gcc, this should work for you. To this end

    1. Download the source tarball.

    2. Unzip with

      tar xjf Python-2.7.2.tar.bz2
      
    3. Build and install with

      cd Python-2.7.2
      ./configure --prefix=/home/username/python --enable-unicode=ucs4
      make
      make install
      

    Now, you have a complete Python installation in your home directory. Pass -I /home/username/python/include to gcc when compiling to make it aware of Python.h. Pass -L /home/username/python/lib and -lpython2.7 when linking.

提交回复
热议问题