oremanj/python-netfilterqueue

NetfilterQueue for Python 3.9

borisarloff opened this issue ยท 5 comments

NetfilterQueue 0.8.1 does not compile for Python 3.9. CPython 3.9 had changes made, with one specific change impacting NFQ. Refer to Python Issue 37250 PyTypeObject.tp_print removed.

The following change removed PyTypeObject.tp_print and replaced it with PyTypeObject.tp_vectorcall_offset: commit aacc77fbd77640a8f03638216fa09372cc21673d

Accordingly, I have monkeypatched netfilterqueue.c to compile under Python 3.9. File is here attached.
netfilterqueue.txt

File renamed from .c to .txt for upload, please rename it back to .c.

Hi, may I ask how to compile/use this netfilterqueue.c to install netfilterqueue Python package?

I am running python 2.7.18 and python 3.9.9 .
I tried replacing you code from netfilterqueue.c into original and tried to install it. It was unsuccessful. Can you advice me on installation please.

following is the Error:

python setup.py install
running install
running build
running build_ext
building 'netfilterqueue' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -ffile-prefix-map=/build/python2.7-qvkjJF/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c netfilterqueue.c -o build/temp.linux-x86_64-2.7/netfilterqueue.o
netfilterqueue.c:4:10: fatal error: Python.h: No such file or directory
    4 | #include "Python.h"
      |          ^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I am running python 2.7.18 and python 3.9.9 . I tried replacing you code from netfilterqueue.c into original and tried to install it. It was unsuccessful. Can you advice me on installation please.

following is the Error:

python setup.py install
running install
running build
running build_ext
building 'netfilterqueue' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -ffile-prefix-map=/build/python2.7-qvkjJF/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c netfilterqueue.c -o build/temp.linux-x86_64-2.7/netfilterqueue.o
netfilterqueue.c:4:10: fatal error: Python.h: No such file or directory
    4 | #include "Python.h"
      |          ^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I tried this and it worked for Python 3.9.2+:

sudo apt-get install build-essential python3-dev libnetfilter-queue-dev
wget https://files.pythonhosted.org/packages/39/c4/8f73f70442aa4094b3c37876c96cddad2c3e74c058f6cd9cb017d37ffac0/NetfilterQueue-0.8.1.tar.gz
gunzip [filename]
tar xvf [filename]
cd [filename]
rm netfilterqueue.c
sudo python3 ./setup.py install

I am running python 2.7.18 and python 3.9.9 . I tried replacing you code from netfilterqueue.c into original and tried to install it. It was unsuccessful. Can you advice me on installation please.
following is the Error:

python setup.py install
running install
running build
running build_ext
building 'netfilterqueue' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -ffile-prefix-map=/build/python2.7-qvkjJF/python2.7-2.7.18=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c netfilterqueue.c -o build/temp.linux-x86_64-2.7/netfilterqueue.o
netfilterqueue.c:4:10: fatal error: Python.h: No such file or directory
    4 | #include "Python.h"
      |          ^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I tried this and it worked for Python 3.9.2+:

sudo apt-get install build-essential python3-dev libnetfilter-queue-dev
wget https://files.pythonhosted.org/packages/39/c4/8f73f70442aa4094b3c37876c96cddad2c3e74c058f6cd9cb017d37ffac0/NetfilterQueue-0.8.1.tar.gz
gunzip [filename]
tar xvf [filename]
cd [filename]
rm netfilterqueue.c
sudo python3 ./setup.py install

It seems this worked for me. Thanks!

Current master should build on 3.9 and I'll be releasing to PyPI shortly.