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:
- cython fuzzy.pyx
- gcc -g -02 -fpic
python-config --cflags
-c fuzzy.c -o fuzzy.o - did the same for double_metaphone.c
- gcc -shared -o fuzzy.so fuzzy.o double_metaphone.o
python-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
forpython3-config
orpython3.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 thepython3.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>
toPyInit_<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 createsinitfuzzy
, and therefore fails to findPyInit_fuzzy
on import.