python h缺_Python:缺少Python.h文件

本文解决了一位Ubuntu 16.04用户在尝试安装Murmurhash python库mmh3时遇到的编译错误问题。通过安装python-dev包及使用pip安装mmh3的方法成功解决了gcc编译过程中出现的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am using Ubuntu 16.04. I am trying to install Murmurhash python library but it is throwing error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 . I looked on Internet and it is says that this error is due to missing python header files. So i did

sudo apt-get install python-dev

but still the error is there. Is the error because i have Anaconda installed or what ? Can somebody help me as in how to rectify this error. Error is as follow :

running install

running build

running build_ext

building 'mmh3' extension

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c mmh3module.cpp -o build/temp.linux-x86_64-2.7/mmh3module.o

cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++

In file included from /usr/include/python2.7/Python.h:81:0,

from mmh3module.cpp:3:

mmh3module.cpp: In function ‘int mmh3_traverse(PyObject*, visitproc, void*)’:

mmh3module.cpp:107:63: error: ‘PyModule_GetState’ was not declared in this scope

#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))

^

/usr/include/python2.7/objimpl.h:326:13: note: in definition of macro ‘Py_VISIT’

if (op) { \

^

mmh3module.cpp:134:14: note: in expansion of macro ‘GETSTATE’

Py_VISIT(GETSTATE(m)->error);

^

In file included from /usr/include/python2.7/Python.h:80:0,

from mmh3module.cpp:3:

mmh3module.cpp: In function ‘int mmh3_clear(PyObject*)’:

mmh3module.cpp:107:63: error: ‘PyModule_GetState’ was not declared in this scope

#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))

^

/usr/include/python2.7/object.h:816:13: note: in definition of macro ‘Py_CLEAR’

if (op) { \

^

mmh3module.cpp:139:14: note: in expansion of macro ‘GETSTATE’

Py_CLEAR(GETSTATE(m)->error);

^

mmh3module.cpp: At global scope:

mmh3module.cpp:143:27: error: variable ‘PyModuleDef mmh3module’ has initializer but incomplete type

static struct PyModuleDef mmh3module = {

^

mmh3module.cpp:144:5: error: ‘PyModuleDef_HEAD_INIT’ was not declared in this scope

PyModuleDef_HEAD_INIT,

^

mmh3module.cpp: In function ‘void PyInit_mmh3()’:

mmh3module.cpp:157:51: error: ‘PyModule_Create’ was not declared in this scope

PyObject *module = PyModule_Create(&mmh3module);

^

In file included from /usr/include/wchar.h:51:0,

from /usr/include/python2.7/unicodeobject.h:120,

from /usr/include/python2.7/Python.h:85,

from mmh3module.cpp:3:

mmh3module.cpp:160:16: error: return-statement with a value, in function returning 'void' [-fpermissive]

return NULL;

^

mmh3module.cpp:107:63: error: ‘PyModule_GetState’ was not declared in this scope

#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))

^

mmh3module.cpp:164:31: note: in expansion of macro ‘GETSTATE’

struct module_state *st = GETSTATE(module);

^

mmh3module.cpp:166:60: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

st->error = PyErr_NewException("mmh3.Error", NULL, NULL);

^

In file included from /usr/include/wchar.h:51:0,

from /usr/include/python2.7/unicodeobject.h:120,

from /usr/include/python2.7/Python.h:85,

from mmh3module.cpp:3:

mmh3module.cpp:169:16: error: return-statement with a value, in function returning 'void' [-fpermissive]

return NULL;

^

mmh3module.cpp:172:12: error: return-statement with a value, in function returning 'void' [-fpermissive]

return module;

^

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

解决方案

I just tried a docker container with ubuntu 16.04

apt-get update

apt-get install -y python-pip

pip install mmh3

That seems to be working. In your machine, you can just try.

sudo apt-get install -y python-pip

sudo pip install mmh3

With this you will be sure whether it is or not an anaconda problem with gcc.

I also checked anaconda with ubuntu 14.04 with the command pip install mmh3. It appears to be working too.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值