相关疑难解决方法(0)

致命错误:Python.h:没有这样的文件或目录

我正在尝试使用C扩展文件构建共享库,但首先我必须使用以下命令生成输出文件:

gcc -Wall utilsmodule.c -o Utilc
Run Code Online (Sandbox Code Playgroud)

执行命令后,我收到此错误消息:

utilsmodule.c:1:20:致命错误:Python.h:没有这样的文件或目录编译终止.

事实上我已经通过互联网尝试了所有建议的解决方案,但问题仍然存在...我也没有问题Python.h.我设法在我的机器上找到该文件......任何人在遇到同样的问题之前?

python gcc python-c-api python-c-extension

1042
推荐指数
27
解决办法
80万
查看次数

Linux上的Twisted安装失败

我试图在我的Linux服务器上从源代码安装在Linux上.当我使用此命令时setup.py install,它失败并显示以下错误消息:

twisted/runner/portmap.c:10:20: error: Python.h: No such file or directory
twisted/runner/portmap.c:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
twisted/runner/portmap.c:31: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
twisted/runner/portmap.c:45: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PortmapMethods’
twisted/runner/portmap.c: In function ‘initportmap’:
twisted/runner/portmap.c:55: warning: implicit declaration of function ‘Py_InitModule’
twisted/runner/portmap.c:55: error: ‘PortmapMethods’ undeclared (first use in this function)
twisted/runner/portmap.c:55: error: (Each undeclared identifier is reported only once
twisted/runner/portmap.c:55: error: for each …
Run Code Online (Sandbox Code Playgroud)

python twisted

17
推荐指数
1
解决办法
1万
查看次数

在python中安装Twisted失败并显示'No such file'

我想在Python中使用Twisted,但是当我安装时,出现此错误,如何处理它?

....
running build_ext
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c conftest.c -o conftest.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c conftest.c -o conftest.o
building 'twisted.runner.portmap' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c twisted/runner/portmap.c -o build/temp.linux-i686-2.7/twisted/runner/portmap.o
twisted/runner/portmap.c:10:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

python linux twisted

14
推荐指数
1
解决办法
9747
查看次数

致命错误:Python.h 没有这样的文件或目录 - 但 python-dev 已安装

我正在尝试在 Ubuntu 上安装 mod_wsgi。当按照 mod_wsgi 网站上的描述运行“sudo make”命令时,我收到错误:

src/server/wsgi_python.h:24:10: fatal error: Python.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

mod_wsgi故障排除部分和 SO(1、2、3)上的其他帖子表示安装正确版本的 python- dev 这已经根据以下输出完成。Python3 运行 3.6.7 和 apt-get 说 python3-dev 是最新版本的 3.6.7。

$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 

$ sudo apt-get install python3-dev
...
python3-dev is already the newest version (3.6.7-1~18.04).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
Run Code Online (Sandbox Code Playgroud)

所以看起来 Python.h 文件在那里但make找不到它。我看了这篇 SO post ( 4 …

python ubuntu mod-wsgi python-3.6

5
推荐指数
1
解决办法
4448
查看次数

从C程序中调用Python函数

我在C中有一个应用程序,在某些时候我需要解决非线性优化问题.不幸的是,AFAIK在C中的资源非常有限(请让我知道其他情况).但是在Python中使用它很简单,例如scipy.optimize.minimize.

当我试图这样做时,我遇到了一些看似非常频繁的陷阱,例如Python.h找不到,模块没有加载,函数调用时出现分段错误等.

什么是快速简便的第一计时器链接这两个程序的方式?

c c++ python python-c-api

2
推荐指数
1
解决办法
2849
查看次数

如何使用Cython将Python 3编译为C语言

我正在尝试将Python 3脚本转换为C,然后将该C文件编译为可执行文件.

我有这个简单的python脚本:

def greet(name = ""):
  print("Hello {0}".format(name if len(name) > 0 else "World"))

greet("Mango")
Run Code Online (Sandbox Code Playgroud)

我使用以下命令将此脚本转换为C:

cython greet.py -o greet.c
Run Code Online (Sandbox Code Playgroud)

然后我使用以下方法编译了C文件:

cc greet.c -o greet
Run Code Online (Sandbox Code Playgroud)

在我输入最后一个命令后,我得到了错误:

致命错误:Python.h:没有终止此类文件或目录编译.

在我收到错误之后,我回过头来意识到我使用的是Python3并且我忘记了"cython"之后的"3".
所以使用以下方法重新编译python脚本:

cython3 greet.py -o greet.c
Run Code Online (Sandbox Code Playgroud)

然后尝试使用以下命令重新编译C文件:

cc greet.c -o greet
Run Code Online (Sandbox Code Playgroud)

再次失败并抛出相同的错误,所以我去搜索SO和谷歌并发现了这些问题:

这些问题中的这些答案都不起作用.

我已经确定我已经安装了所有正确依赖项的cython,apt-get install并且pip install遗憾地认为它似乎仍然不起作用.

c python linux cython ubuntu-16.04

2
推荐指数
1
解决办法
1万
查看次数

如何使用嵌入式python脚本编译和运行C代码?

我正在使用python 文档中的这个例子

#include <Python.h>
int
main(int argc, char *argv[])
{
  Py_SetProgramName(argv[0]);  /* optional but recommended */
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print('Today is', ctime(time()))\n");
  Py_Finalize();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

其中 python 脚本被硬编码为 C 程序。但是当我尝试编译它时

$ gcc -c modwithpy.c -o mod
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

modwithpy.c:1:20: 致命错误: Python.h: 没有这样的文件或目录编译终止。

但是,我已经安装了python-dev包。我还查看了编译和链接文档,但不明白我需要编写的 python 包的绝对路径。

$ whereis python
python: /usr/bin/python3.3m /usr/bin/python /usr/bin/python2.7-config 
/usr/bin/python3.3 /usr/bin/python2.7 /etc/python /etc/python3.3 /etc/python2.7
/usr/lib/python2.6 /usr/lib/python3.3 /usr/lib/python2.7 /usr/bin/X11/python3.3m
/usr/bin/X11/python /usr/bin/X11/python2.7-config /usr/bin/X11/python3.3
/usr/bin/X11/python2.7 /usr/local/lib/python3.3 /usr/local/lib/python2.7
/usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
Run Code Online (Sandbox Code Playgroud)

c python

1
推荐指数
1
解决办法
1729
查看次数