【问题标题】:Python: Python.h file missingPython:缺少 Python.h 文件
【发布时间】:2016-08-21 20:32:33
【问题描述】:

我使用的是 Ubuntu 16.04。我正在尝试安装 Murmurhash python 库,但它抛出错误: command 'x86_64-linux-gnu-gcc' failed with exit status 1 。我在互联网上查看,据说这个错误是由于缺少 python 头文件造成的。所以我做到了

sudo apt-get install python-dev  

但错误仍然存​​在。错误是因为我安装了 Anaconda 还是什么?有人可以帮助我如何纠正这个错误。错误如下:

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

【问题讨论】:

  • Python 包的 C++ 部分似乎有问题,因此无法编译。
  • @KlausD。但同样在 Ubuntu 12.04 中运行
  • 多年来,GCC 变得更加严格。您可以通过设置正确的标志来抑制错误来手动编译。您可以在行尾的[ ] 中看到它们。

标签: python gcc anaconda murmurhash


【解决方案1】:

我刚刚尝试了一个带有 ubuntu 16.04 的 docker 容器

apt-get update
apt-get install -y python-pip
pip install mmh3

这似乎奏效了。在你的机器上,你可以试试。

sudo apt-get install -y python-pip
sudo pip install mmh3

这样你就可以确定gcc是否是anaconda问题。

我还使用命令pip install mmh3 使用 ubuntu 14.04 检查了 anaconda。它似乎也有效。

【讨论】:

    猜你喜欢
    • 2013-05-03
    • 2021-04-20
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    • 2018-11-25
    • 2018-10-16
    • 2020-10-27
    • 2018-11-06
    相关资源
    最近更新 更多