Search code examples
python-3.xraspberry-pi3raspbianscapydnp3

why (ModuleNotFoundError: No module named 'scapy') shows up?


I wrote a program using python3 which read and responses data via DNP3 protocol, It is intended to be run on a rpi3 I wrote the code on my laptop then took it to the rpi, installed all the dependencies but I get an error which I don't know what to do with: ModuleNotFoundError: No module named 'scapy' I installed scapy with pip install scapy successfully.

I'm newbie to Python, please help me out, tnx

I don't think it's related, but here's a piece of code:

outstation.py :

    from dnp3_lib import *
    import datetime
    from struct import pack, unpack
    import sys
    import socket
    import random

    SRC = 1023
    DEST = 1010
    START_B = b'\x05\x64'
    port = 20000

    transport_sequence = 0

    try:
        s = socket.socket()          
        print ("Socket successfully created!")                

        s.bind(('', port))         
        print ("Socket binded to %s" %(port)) 

        s.listen(5)      
        print ("Socket is Listening...")            

        # Establish connection with client. 
        c, addr = s.accept()      
        print ('Got connection from', addr)
        # counter = 0

        while True:
            try:
                # Handle the requests and responces
            except Exception as e:
                print (e)
                c.close()
                exit()
        c.close()
    except socket.error:
        print (">>> an err occurred !" + socket.error)
        c.close()
        exit()

dnp3_lib.py :

from scapy.all import *
import crcmod.predefined
import string
from struct import pack, unpack
.
.
.
# some functions to handle CRC and other things

EDIT:

I've commented the from scapy.all import * and it shows (ModuleNotFoundError: No module named 'crcmod'). I've installed crcmod using pip.


Solution

  • On many systems pip defaults to version 2, rather than version 3. It is a best practice to always specify which version you want by entering either pip2 or pip3 instead of using the default pip.

    In this case, running pip3 install scapy should resolve the error.

    EDIT: You will additionally need to run pip3 install crcmod, likewise for each other package that your script depends on.