How to install Python libpcap module on Mac OS X

14.7k views Asked by At

I started to work on a python sniffer project. I want to use the pcap module but my computer always says "No module named pcap". I read that libpcap and pcap come with OS X but actually, it doesn't work...

I made a lot of research on the web and still unable tu run my python code. How am I supposed to do for running / linking or installing pcap ?

Note that I recently update to OSX Yosemite (but I didn't know if pcap worked before).

2

There are 2 answers

2
Quentin On BEST ANSWER
  1. Install brew from here
  2. Run brew doctor from terminal
  3. Solve the warnings from brew doctor results
  4. Run sudo easy_install pyrex
  5. Run sudo easy_install pypcap

=> This solved my problem (don't really know if brew is necessary)

1
Andrew Jaffe On

I think the library libpcap exists on OS X, but you are looking for a python module to which wraps it. I think the one you want is actually called pypcap, although I have no idea if that's the right/best one(*). You should be able to install it with either

easy_install pypcap

or

pip install pypcap

depending on the details of your python installation. (You also need to make sure that pip and/or easy_install are installing in a place known to the python installation that you're using; this may depend on which python it is -- Apple's, python.org, brew, etc. -- and how you've set it up.)

(*) I don't even know what pcap does, so note that there are a lot of pcap-related modules listed on PyPi.