Installing Scapy on a Mac: "ImportError: No module named pcapy" - python

I'm trying to run a python script that involves scapy but I can't seem to get it to run. I keep getting this error
ImportError: No module named pcapy
The script I'm trying to run is:
from scapy.all import *
def arp_display(pkt):
if pkt[ARP].op == 1: #who-has (request)
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
print "ARP Probe from: " + pkt[ARP].hwsrc
print sniff(prn=arp_display, filter="arp", store=0, count=10)
I've installed XCode, XQuartz, Python, and Scapy using macports
Please let me know what I'm missing! #noob

I had the same problem. I solved this using following steps:
1.) Open terminal and enter the command
sudo pip install --user pcapy
2.) Enter
python
in your terminal
3.) Enter the command
import pcapy
This should fix your problem.
Best regards,
Nazar Medeiros

Try installing libpcap and its Python wrapper from source, as listed here, though the latest version is 0.6.4 and not 0.6.2:
$ wget http://dfn.dl.sourceforge.net/sourceforge/pylibpcap/pylibpcap-0.6.4.tar.gz
$ tar xfz pylibpcap-0.6.4.tar.gz
$ cd pylibpcap-0.6.4
$ sudo python setup.py install

Download the latest version of pcapy from this link
https://www.coresecurity.com/corelabs-research/open-source-tools/pcapy
Unpack it and from the directory run the following command:
python setup.py install

Related

Use wget or curl from python in Windows CMD

I'm pretty new to Python. I have installed Python 3.7.3 on my Windows and would like to use CMD to run a .py file.
The commands are like py xxx.py and it is actually for downloading some files from a server.
When it asks "Is it OK to download", I hit yes.
Then a message appeared.
The script will need curl or wget on the system, please install them
first before running the script !
The program will exit then.
But when I try to run pip install wget this message appears:
Requirement already satisfied: wget in
c:\users\qin_l\appdata\local\programs\python\python37-32\lib\site-packages
(3.2)
And when I input py -m wget xxx.file, I can download the file (not the one I want)
I guess the part that cannot go through windows is
# Check if curl or wget commands exsit on your computer
if sys.version_info >= (3,0):
status_curl, result = subprocess.getstatusoutput('which curl')
status_wget, result = subprocess.getstatusoutput('which wget')
else:
status_curl, result = commands.getstatusoutput("which curl")
status_wget, result = commands.getstatusoutput("which wget")
And correspondingly
if status_curl == 0:
cmd='curl -g "'+cmd+'" -o '+ ncout
elif status_wget == 0:
cmd='wget "'+cmd+'" -O '+ ncout
else:
sys.exit('\nThe script will need curl or wget on the system, please install them first before running the script !\nProgram will exit now !\n')
It seems wget can work in Python but not in the py file. I am super confused here. Do I have to install Linux and run the command in Ubuntu?
The script you have is expecting wget or curl to be installed as command line tools, ie. you can run them from the CMD prompt.
Confusingly, there is also a python package called wget, which was installed with pip install wget, but it's completely different..
To install command line wget, first install Scoop using Powershell, then install install wget with scoop install wget.
I tried to change 'which curl' to 'where curl' and no error messages anymore. But was not able to download the files because "Disabling SSL due to encountered errors".
Turned to I have to install Ubuntu in my computer, and it finally works.

Can not run signalR client on Python

I am running some Python code on Raspberry Pi and now I need real time communication. I have a SignalR hub hosted on Azure and in order to connect to it I am using this python client. Since I am quite new to python I have some lame questions:
After I did pip install signalr-client I tried pip install -r requirements but then nothing happens. I just get an error Could not open requirements file: [Errno 2] No such file or directory: 'requirements' As I understood this is some kind of a file which contains some references but not really sure how it is supposed to execute.
After the failure with installing pip install -r requirements I decided to try it directly as it is right now and I copied the code from the sample (modified with the metadata for my hub). Once I try to run it I get an error on the second line from signalr import Connection saying that there's no such module as signalr. Do you have any idea what could be this and is there any chance for those two to be related?
NOTE: When I execute pydoc modules I can see it there in the list.
Also, regarding python and pip versions I get:
python -V : Python 2.7.13
pip -V : pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

Can't install BigARTM python library on linux

I'm trying to install BigARTM on my mint following this instruction, all steps seems to be passed successful, for example last one:
*#*​-PC ~ $ cd ~/bigartm/python
​*#*​-PC ~/bigartm/python $ sudo python setup.py install
returns: ...Finished processing dependencies for bigartm==0.8.0
So import artm gives me import error (this is how it might be imported)
What might be wrong?

"ImportError: No module named twilio.rest"

I have installed python 2.7.10 with PATH access and correctly installed twilio. However, when I try to execute a code I get this error message
Traceback (most recent call last):
File "C:\Users\tmslvo\Google Drive\Desktop\send text.py", line 1, in <module>
from twilio.rest import TwilioRestClient
ImportError: No module named twilio.rest
Now I read that a reason might be that python can't find the twilio package so I tried the
which -a python
which -a twilio
commands (in my Windows command prompt) in which case I get
'which' is not recognized as an internal or external command,
operable program or batch file.
Does anybody have an idea of what I'm doing wrong?
Thank you!
Twilio developer evangelist here.
I think your problem will be that somehow when you installed the library, it failed silently(?). A few things to keep in mind:
When installing Python libraries, always make sure you use pip.
Also, check that none of your files within the project are actually called twilio.py as this will conflict with the actual library.
Check that you're using the version of Python you think you're using by running python --version
All that failing, run the installation again, and all going well (without errors), you should be able to test it quickly with the following code.
import twilio
import twilio.rest
try:
client = twilio.rest.TwilioRestClient(account_sid, auth_token)
message = client.messages.create(
body="Hello World",
to="+14159352345",
from_="+14158141829"
)
except twilio.TwilioRestException as e:
print e
try this: sudo pip3 install twilio --upgrade
I had this problem as well.
In my case, I had named my file twilio.py and that is what caused the error.
Renaming the file to send_sms.py ( or any other name of your choice) will resolve the issue!
Close and then relunch all IDLE instances.
This sounds obvious but it worked for me, since the installations of components were successful
I ran into this same issue. I had used easy_install instead of pip to install twilio which was the problem. To fix this I ran pip uninstall twilio and reinstalled using pip.
rename file name other than twilio.py
EX:send_sms.py
A bit late to the party here but I also ran into this issue.
After some trial and error, it looks like it was due to the pip version I was using. I originally used -
pip3 install twilio.
Now I'm unsure of the underlying reason why this did not work, but it seems that pip3 does not encompass all versions of python 3.x? Using
pip3 list and
pip3.8 list
I noticed I had the twilio module for pip3 but not for pip 3.8.
I used the following and was able to solve the issue
pip3.8 install twilio.
I used pip3.8 because that matched the python3.8 version that I am using.
Pycharm user:
Macs (mid 2017) come with python 2.6 and 2.7 installed. PyCharm uses by default 2.6. When you install twilio (Pip install) the module is installed in python version 2.7. So, when you try to run twilio from PyCharm you get
ImportError: No module named twilio.rest
Solution: change the python interpreter in PyCharm. Go to preferences > project interpreter and from the drop menu Project Interpreter choose python 2.7
I think your pip is not configured properly . You may be getting succefuuly installed message but it is not install where it should be. try pip install --user i am sure it will work for you. pip install may work fine only in virtualenvironment without any config.Try pip install --user package name
#iosCurator
I had first installed twilio with the easy_intall tool
I followed the steps below:
Uninstall twilio with the command pip uninstall twillo
Install twilio with the command pip install twilio
Close the python IDLE and relaunch it.
For the windows user,
I have suggested, pip3 install twilio
Follow these steps (on mac):
Shift + Command + P
search: Configure Language Specific Setting
search: Python
add: "code-runner.runInTerminal": true
That's it!
Ask me any question about it by:
My LinkedIn
I ran into this issue when using poetry for my dependency management. Poetry doesn't recognise it as an existing package yet, hence it won't run your code unless you try the poetry+pip way.
there will be 2 reasons for this
1.make sure you kept right path for python files in environment location
2.install twilio
commands:
1.pip3 install twilio
(or)
pip install twilio
2.python otpv.py

how to install pcap in ubuntu using python

this is my code :
import pcap ,struct
pack=pcap.pcap()
pack.setfilter('udp')
key=''
for recv_time,recv_data in pack:
recv_len=len(recv_data)
if recv_len == 102 and recv_data[42]== chr(02) and recv_data[101] == chr(03):
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
elif recv_len == 55:
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
and i use this to install pcap :sudo apt-get install python-libpcap , it installed ,
but when i run the code , it show error :
Traceback (most recent call last):
File "weapon.py", line 2, in <module>
import pcap ,struct
ImportError: No module named pcap
what can i do ,
thanks
For me on Ubuntu 10.04 the package is called python-libpcap:
sudo apt-get install python-libpcap
Then when I do:
import pcap
It works great!
I'm guessing the installed module doesn't match the version of python you're running.
Look in /usr/lib/python2.7/dist-packages/ and see if pcap is there (substituting the version you're using for 2.7).
You need to make sure that you have pip installed.
sudo apt-get install python-pip
Then you can install pypcap:
sudo easy_install pypcap
sudo pip install pypcap
I verified it for Ubuntu 14.10.

Categories