如何在c中扩展python?

发布于 2024-10-03 18:50:27 字数 843 浏览 1 评论 0原文

我擅长Python编程。我正在尝试用我自己的C程序来扩展Python。 我有一些教程,但我的操作系统非常蹩脚。它说

找不到 python.h

我也尝试过在其中进行 OpenGL 编程。 我不得不面对类似的错误

未找到 GL/gl.h

我想我的 Linux 上没有 GL dev-library。但我非常确定 python.h 位于我的硬盘上,因为我在正确的目录中找到了它。

我使用的是 PCLinux 操作系统 2010 采用 Intel 1.8GHz Q2duo 的戴尔 Vostro 1510
2Gb 内存
gcc4.4.1

我无法在 Windows 上使用 Swig,因为我无法在其上安装 gcc。 Swig 无法在我当前的操作系统上运行。如果我自己写代码,就会出现这样的错误。 (我确信代码的完整性,因为它是一个示例文件)

请告诉我在我当前的操作系统中编译 .so 文件以扩展 python 的过程

请告诉我哪种操作系统最适合这种编程工作。

请告诉我如何将所有功能安装到 Windows 中以完成这项工作。

有没有一个IDE可以帮助我解决这个问题。

请帮我。为了做到这一点,我已经挠头很长时间了。 我厌倦了理想化的教程,这些教程假设理想的功能计算机一切正常。谢谢,

我不是专业程序员。但我做了一些非常有趣的事情。我已经学习了 Turbo c++.gcc 编程对我来说并不新鲜。请考虑我的新手问题。

I'm good at Python programming.I'm trying to extend python with my own c programs.
I've got some tutorials but my operating system is pretty lame. It says that

python.h is not found

Also I've tried OpenGL programming in it.
I had to face similar error

GL/gl.h not found

I think I don't have GL dev-library on my Linux. But I'm damn sure that python.h is on my Hard drive, because I've found it in the proper directory.

I'm using PCLinux OS 2010
Dell Vostro 1510 with Intel 1.8GHz Q2duo
2Gb ram
gcc4.4.1

I can't use Swig on windows because I couldn't install gcc on it.
Swig wont run on my current OS. If I write the code by myself, it shows this kind of error.
(I'm sure of the code's integrity because it was an example file)

Please tell me the procedure to compile a .so file for extending python in my current OS
OR
Please tell me which OS works best for this kinda programming stuff.
OR
Tell me if How I can install all the features into Windows for this work.
OR
Is there an IDE which can help me out with this kinda problem.

Please Help me. I've been scratching my head for pretty long time trying to do this.
I'm tired of idealized tutorials which assume of ideal functional computer where every thing works. Thank you

I'm not an expert programmer. But I've done some pretty interesting things. I have learn programming on turbo c++.gcc is little new to me. Please consider my novice question.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

So要识趣 2024-10-10 18:50:27

就在 PCLinux 上编译这些东西而言,看来你确实缺少头文件。

您需要通过包管理器安装它们:

sudo apt-get install python-devel
sudo apt-get install libnvidia-xorg1-devel

这将安装 python 标头、OpenGL 标头。

至于让这些东西在 Windows 上运行,您需要设置一个 posix 环境(cygwin 或 mingw)以便能够在那里使用 gcc,有关该主题的更多信息可以在这个问题中找到:
Cygwin 和 MinGW 有什么区别?

更新
我读了一些有关 PCLinuxOS 的内容,它似乎非常糟糕,这意味着它缺少存储库中的很多东西。

我给你的建议是使用 Ubuntu 进行开发,因为:

  1. Ubuntu 的用户群比PCLinux
  2. 这里的许多人在 Ubuntu 上进行积极的开发
  3. Ubuntu 的存储库维护得更好,而且几乎没有什么是不能通过 apt 获得的,
  4. 因此让你的 python c 扩展在那里运行将是微不足道的< /strong>
  5. 最后但并非最不重要的一点是,由于上述事实,未来的问题将得到更多答案,如果您遇到 Ubuntu 本身的问题,甚至还有一个 stackexchange 站点

使用良好的开发环境可以为您节省大量时间并减少麻烦。

更新 2 在 Ubuntu 上安装标头

sudo apt-get install python-dev
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install libglew1.5-dev

这将安装 python 标头、OpenGL 标头、OpenGL 实用程序标头和 OpenGL 扩展标头。

As far as compiling the stuff on PCLinux goes, it seems that you're indeed missing the header files.

You need to install them via the package manager:

sudo apt-get install python-devel
sudo apt-get install libnvidia-xorg1-devel

This will install the python headers, the OpenGL headers.

As far as getting the stuff to run on windows goes, you'll need to setup a posix environment (either cygwin or mingw) in order to be able to use gcc there, more on that topic can be found in this question:
What is the difference between Cygwin and MinGW?

Update
I read a bit about PCLinuxOS, it seems to be pretty bad, that means it's missing a lot of stuff from its repositories.

My suggestion to you is to use Ubuntu for development since:

  1. Ubuntu's user base is a lot bigger than the one of PCLinux
  2. Many people here do active development on Ubuntu
  3. Ubuntu's repositories are a lot better maintained and there's nearly nothing one can't get via apt
  4. Therefore getting your python c extension to run there will be trivial
  5. And last but not least future questions will get a lot more answers due to the above facts, and if you got problems with Ubuntu itself there's even a stackexchange site

Using a good development environment saves you a lot of time and headaches.

Update 2 Installing the headers on Ubuntu

sudo apt-get install python-dev
sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglu1-mesa-dev
sudo apt-get install libglew1.5-dev

This will install python headers, OpenGL headers, OpenGL utility headers and OpenGL extensions headers.

不甘平庸 2024-10-10 18:50:27

根据我的经验,您需要在系统上安装 Python 开发库,然后通过编写 C 代码然后使用 Python 解释器编译该 C 代码来扩展 Python。例如,请参阅文章如何扩展 Python

In my experience, you need to have the Python development libraries installed on your system and you extend Python by writing your C code then compiling that C code using the Python interpretor. See for example the article How to extend Python.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文