我有我的Python Ubuntu系统上,但GCC找不到Python.h [英] I have Python on my Ubuntu system, but gcc cant find Python.h

查看:378
本文介绍了我有我的Python Ubuntu系统上,但GCC找不到Python.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是学计算机的,所以我不能安装任何东西。

我想创建C $ C $Ç可以在Python运行。似乎所有我在上面找到的文章需要你使用

 的#include< Python.h>

我这样做,但是当我编译它抱怨的没有这样的文件或目录。

计算机有Python的(至少它在终端蟒蛇命令,我们可以运行我们想要的任何Python的code)。

我输入终端定位Python.h ,但一无所获。

我有两个问题:


  1. 我可以写C code,我可以在Python呼叫而不 Python.h


  2. 我失去了一些东西,并且计算机实际上有 Python.h



解决方案

在Ubuntu中,你需要安装一个叫做包中的python-dev的。由于这个包好像没有安装(定位Python.h 没发现什么),你可以不安装它的系统范围内的自己,我们需要一个不同的解决方案。

您可以在你的home目录安装Python - 你不需要任何特殊权限做到这一点。如果你被允许使用网络浏览器,并运行一个gcc,这应该为你工作。为此

  

  1. 源码包。


  2. 解压缩与

    焦油XJF的Python-2.7.2.tar.bz2


  3. 构建和安装

    CD的Python 2.7.2
    的./configure - preFIX = /家庭/用户名/蟒蛇--enable-UNI code = UCS4
    使
    使安装


现在,你在你的home目录的完整的Python安装。通 -I /家/用户名/蟒蛇/包括来的gcc编译时让它知道 Python.h 的。通 -L /家/用户名/ Python的/ lib目录 -lpython2.7 链接时。

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 require you to use

#include <Python.h>

I do this, but when I compile it complains that there is no such file or directory.

The computer has Python (at least it has the python command in the terminal, and we can run whatever Python code we want).

I typed in locate Python.h in the terminal, but it found nothing.

I have two questions:

  1. Can I write C code that I can call in Python without Python.h?

  2. Am I missing something, and the computer actually has Python.h?

解决方案

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.

这篇关于我有我的Python Ubuntu系统上,但GCC找不到Python.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆