衫裤跑路 2018-10-24 02:03 采纳率: 50%
浏览 1429

C Python Module — ImportError: Symbol not found: _Py_InitModule4_64

I am beginning the process of writing Python 3 module in C. The C I have written already compiles fine (code I compiled at bottom of post). I compile with:

python3 setup.py build_ext --inplace

The built .so file is placed in the current directory. After launching python3, when I import my module I get this error (tripple dot used to truncate paths):

>>> import helloWorld
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(..., 2): Symbol not found: _Py_InitModule4_64
  Referenced from: .../helloWorld.cpython-36m-darwin.so
  Expected in: flat namespace
 in .../helloWorld.cpython-36m-darwin.so

How do I got about getting symbol _Py_InitModule4_64 implemented?

I am running macOS High Sierra if that means anything


Running nm for helloWorld.cpython-36m-darwin.so shows _Py_InitModule4_64 is undefined, so does that prove there is an issue in the compilation process?

nm helloWorld.cpython-36m-darwin.so 
                 U _Py_BuildValue
                 U _Py_InitModule4_64
0000000000000eb0 t _helloWorld
0000000000001060 d _helloWorld_docs
0000000000001020 d _helloworld_funcs
0000000000000e80 T _inithelloWorld
                 U dyld_stub_binder

Code

test.c:

#include <Python/Python.h>

static PyObject* helloWorld(PyObject* self) {
   return Py_BuildValue("s", "Hello, Python extensions!!");
}

static char helloWorld_docs[] =
   "helloWorld( ): Any message you want to put here!!\n";

static PyMethodDef helloworld_funcs[] = {
   {"helloWorld", (PyCFunction)helloWorld,
   METH_NOARGS, helloWorld_docs},
   {NULL}
};

void inithelloWorld(void) {
   Py_InitModule3("helloworld", helloworld_funcs, "Extension module example!");
}

setup.py:

from distutils.core import setup, Extension

setup(name = 'helloWorld', version = '1.0', \
    ext_modules = [Extension('helloWorld', ['test.c'])])

转载于:https://stackoverflow.com/questions/52960112/c-python-module-importerror-symbol-not-found-py-initmodule4-64

  • 写回答

1条回答 默认 最新

  • devmiao 2018-10-26 07:05
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog