ImportError: dynamic module does not define module export function
Robert Simmons <[email protected]> Thu, 21 Nov 2024 16:26:29 -0500
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CA+QLa9DZL_6Pm1F2Y9KRv8QsvOAzCfmu-LkE4msMtPLAgSQFjA@mail.gmail.com> |
--===============8399119697311934270==
Content-Type: multipart/alternative; boundary="000000000000124a98062772ecb7"
--000000000000124a98062772ecb7
Content-Type: text/plain; charset="UTF-8"
When importing a hello world, I'm seeing an exception being raised. Any
help would be appreciated.
>>> import hello
Traceback (most recent call last):
File "<python-input-0>", line 1, in <module>
import hello
ImportError: dynamic module does not define module export function
(PyInit_hello)
I see someone had a similar issue and was directed to ask here:
https://github.com/swig/swig/discussions/2961
I also see the following:
https://pythonextensionpatterns.readthedocs.io/en/latest/miscellaneous.html
I am on macOS, so I've examined the .so in the same way below.
Here is the directory structure:
README.md
pyproject.toml
src
src/hc
src/hc/hello.c
src/hc/hello.i
Here is the SWIG interface file:
%module hello
%{
void say_hello();
%}
void say_hello();
Here is the C:
#include <stdio.h>
void say_hello() {
printf("Hello, World!\n");
}
here is the contents of pyproject.toml
[build-system]
requires = ["setuptools>=75.6"]
build-backend = "setuptools.build_meta"
[project]
name = "helloc"
version = "0.0.1"
authors = [
{ name = "Foo" }
]
description = "Hello world SWIG C"
readme = "README.md"
requires-python = ">=3.13"
classifiers = [
"Development Status :: 1 - Planning",
"License :: Public Domain",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.13"
]
[tool.setuptools]
ext-modules = [
{ name = "hello", sources = ["src/hc/hello.c", "src/hc/hello.i"] }
]
Here is nm output:
% nm -m lib.macosx-14.0-x86_64-cpython-313/hello.cpython-313-darwin.so |
grep Init
0000000000001140 (__TEXT,__text) external _PyInit__hello
0000000000004120 (__DATA,__data) non-external _PyInit__hello.SWIG_module
--000000000000124a98062772ecb7
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">When importing a hello world, I'm seeing an exception =
being raised. Any help=C2=A0would be appreciated.<div><br></div><div>>&g=
t;> import hello<br>Traceback (most recent call last):<br>=C2=A0 File &q=
uot;<python-input-0>", line 1, in <module><br>=C2=A0 =C2=
=A0 import hello<br>ImportError: dynamic module does not define module expo=
rt function (PyInit_hello)</div><div><br></div><div>I see someone had a sim=
ilar issue and was directed to ask here:</div><div><a href=3D"https://githu=
b.com/swig/swig/discussions/2961">https://github.com/swig/swig/discussions/=
2961</a></div><div><br></div><div>I also see the following:</div><div><a hr=
ef=3D"https://pythonextensionpatterns.readthedocs.io/en/latest/miscellaneou=
s.html">https://pythonextensionpatterns.readthedocs.io/en/latest/miscellane=
ous.html</a></div><div><br></div><div>I am on macOS, so I've examined t=
he .so in the same way below.</div><div><br></div><div>Here is the director=
y structure:</div><div><br></div><div>README.md<br>pyproject.toml<br>src<br=
>src/hc<br>src/hc/hello.c<br>src/hc/hello.i</div><div><br></div><div>Here i=
s the SWIG interface file:</div><div><br></div><div>%module hello<br><br>%{=
<br>void say_hello();<br>%}<br><br>void say_hello();</div><div><br></div><d=
iv>Here is the C:</div><div><br></div><div>#include <stdio.h><br><br>=
void say_hello() {<br>=C2=A0 =C2=A0 printf("Hello, World!\n");<br=
>}<br><br>here is the contents of pyproject.toml<br><br>[build-system]<br>r=
equires =3D ["setuptools>=3D75.6"]<br>build-backend =3D "=
setuptools.build_meta"<br><br>[project]<br>name =3D "helloc"=
<br>version =3D "0.0.1"<br>authors =3D [<br>=C2=A0 =C2=A0 { name =
=3D "Foo" }<br>]<br>description =3D "Hello world SWIG C"=
;<br>readme =3D "README.md"<br>requires-python =3D ">=3D3=
.13"<br>classifiers =3D [<br>=C2=A0 =C2=A0 "Development Status ::=
1 - Planning",<br>=C2=A0 =C2=A0 "License :: Public Domain",=
<br>=C2=A0 =C2=A0 "Natural Language :: English",<br>=C2=A0 =C2=A0=
"Operating System :: OS Independent",<br>=C2=A0 =C2=A0 "Pro=
gramming Language :: Python",<br>=C2=A0 =C2=A0 "Programming Langu=
age :: Python :: 3",<br>=C2=A0 =C2=A0 "Programming Language :: Py=
thon :: 3 :: Only",<br>=C2=A0 =C2=A0 "Programming Language :: Pyt=
hon :: 3.13"<br>]<br><br>[tool.setuptools]<br>ext-modules =3D [<br>=C2=
=A0 { name =3D "hello", sources =3D ["src/hc/hello.c", =
"src/hc/hello.i"] }<br>]</div><div><br></div><div>Here is nm outp=
ut:</div><div><br></div><div>% nm -m lib.macosx-14.0-x86_64-cpython-313/<a =
href=3D"http://hello.cpython-313-darwin.so">hello.cpython-313-darwin.so</a>=
| grep Init<br>0000000000001140 (__TEXT,__text) external _PyInit__hello<br=
>0000000000004120 (__DATA,__data) non-external _PyInit__hello.SWIG_module</=
div></div>
--000000000000124a98062772ecb7--
--===============8399119697311934270==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--===============8399119697311934270==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
--===============8399119697311934270==--