I am using Python3.4 and I am trying to install the module fuzzy
https://pypi.python.org/pypi/Fuzzy.
Since it is mentioned it works only for Python2, I tried to convert it using cython. These are the steps that I followed:
python-config --cflags
-c fuzzy.c -o fuzzy.opython-config --libs
When I tried to import fuzzy I got an error:
dynamic module does not define init function (PyInit_fuzzy)
What is the issue? Is this because of the python2 and python3 clash? How to resolve this?
This was solved with a quick comment, but posted as an answer for the sake of giving a bit more detail...
The very short answer is to replace all instances of python-config
for python3-config
or python3.4-config
.
Unnecessary detail follows
OP was trying to use a Pyrex module in Python 3 (this isn't especially clear from the question), and hence rebuilding it in Cython is a sensible approach to take, since Cython was originally based on Pyrex.
Cython generates code that should compile to work in Python 2 or 3, depending on which headers are included. python-config
generates relevant compiler/linker options for the default version of Python on the system which at the time of writing is typically Python 2 (on my system it includes -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7
). Therefore it builds the module for Python 2. Using the python3.4-config
ensures that the right version is included.
In the changeover from Python 2 to Python 3 the function called when C modules are imported was changed from init<modulename>
to PyInit_<modulename>
, presumably to help ensure that you can only import modules built for the correct version. Therefore when the module is built with Python 2 it only creates initfuzzy
, and therefore fails to find PyInit_fuzzy
on import.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With