2

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.

Community
  • 1
  • 1
Arian Sakhaei
  • 151
  • 1
  • 4
  • 15

2 Answers2

4

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.

0

In my case I was trying to import tensorflow_data_validation and I got the same error that (ModuleNotFoundError: No module named 'crcmod'). When I tried to pip install crcmod I got the message that crcmod already exists. I even tried uninstalling and installing the package and it didn't work.

At last what solved my problem was running pip uninstall crcmod and then reinstalling it using conda, conda install -c conda-forge crcmod. Now it works perfectly.

Amir Zare
  • 453
  • 1
  • 4
  • 15