pynetwork / pypcap

pypcap - python libpcap module, forked from code.google.com/p/pypcap
Other
299 stars 74 forks source link

Python 3 support #24

Closed brifordwylie closed 6 years ago

brifordwylie commented 8 years ago

We'd like to have pypcap support Python3, so we'll need to make sure setup/install and functionality all works with Python3.

sgould420 commented 7 years ago

@brifordwylie: I confirmed the problem when trying to import the module on python3 from PR #19. I am on OS X El Capitan, 10.11.5, with python 3.5.1.

Python 3.5.1 (default, Jan 19 2016, 14:01:03) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/pcap.cpython-35m-darwin.so, 2): Symbol not found: _PyBuffer_FromMemory
  Referenced from: /usr/local/lib/python3.5/site-packages/pcap.cpython-35m-darwin.so
  Expected in: flat namespace
 in /usr/local/lib/python3.5/site-packages/pcap.cpython-35m-darwin.so
>>> 

Note: I installed by using pip3 download pypcap then tar -xvf pypcap-1.1.5.tar.gz, modified setup.py as in commit https://github.com/pynetwork/pypcap/pull/18/commits/10621117d44906898e21b50abb80d8a1f79e019e to add the parentheses for python3 style print function, and also changed the line 45 to lib_sub_dirs = [os.path.join('/usr', sub_dir) \ as in the comment from @phirestalker on https://github.com/dugsong/pypcap/issues/49, and then running sudo pip3 install ./pypcap-1.1.5 That second fix did work fine to solve the AttributeError: 'NoneType' object has no attribute 'rfind' error in python2 on the same system.

plison commented 7 years ago

I can also confirm that the installation with pip3 is broken!

claycollier commented 7 years ago

Python3 removed the buffer API that was used to build the C extensions for 2.7. I have a version of pcap.pyx for Python3 that works on my machine, but I'm not sure how to build a version that supports both Python3 and 2.7. It appears that all that needs to happen is to change the calls to PyBuffer_FromMemory() to PyMemoryView_FromMemory() and regenerate the .c file using cython, but I haven't done any deep testing because the test scripts have version issues as well (like no clean dpkt installer for Python3).

hellais commented 7 years ago

Python3 removed the buffer API that was used to build the C extensions for 2.7. I have a version of pcap.pyx for Python3 that works on my machine, but I'm not sure how to build a version that supports both Python3 and 2.7. It appears that all that needs to happen is to change the calls to PyBuffer_FromMemory() to PyMemoryView_FromMemory() and regenerate the .c file using cython, but I haven't done any deep testing because the test scripts have version issues as well (like no clean dpkt installer for Python3).

This is great!

Could you submit a PR with the changes you made to it and I can take a look at it. If it's not possible to have a c extension that works both on python2 and python3, we can build two versions of it and use one of the other in the setup.py depending on the detected version.

nuald commented 7 years ago

Fixed in #47. Need to verify across the various use-cases with the different Python versions though.

lambdalisue commented 7 years ago

When is feature/python3 merged to the master and uploaded to PyPI? I'm using that branch and seems ready. I'm looking forward.

hellais commented 7 years ago

When is feature/python3 merged to the master and uploaded to PyPI? I'm using that branch and seems ready. I'm looking forward.

Thanks for the input on that. I haven't gotten around to testing it extensively yet, but will try to bump it a bit up in my priorities and see if we can get something pushed sometime next week.

lambdalisue commented 7 years ago

Thanks! I'm lookin' forward it's on PyPI:)

hellais commented 6 years ago

This is implemented.