无法使用使用 pyshark 的 pypy3 脚本运行

发布于 2025-01-14 21:06:48 字数 1796 浏览 2 评论 0原文

这里我尝试使用 pypy3 c.py 运行脚本,但出现了上述错误, 我安装了 pypy3 -m pip install pyshark 但是...

pypy3 c.py

ModuleNotFoundError:没有名为“lxml.objectify”的模块

import pyshark
import pandas as pd
import numpy as np
from multiprocessing import Pool
import re
import sys

temp_array  = []

cap = pyshark.FileCapture("ddos_attack.pcap")
#print(cap._extract_packet_json_from_data(cap[0]))

def parse(capture):
    print(capture)
    packet_raw = [i.strip('\r').strip('\t').split(':') for i in str(capture).split('\n')]
    packet_raw = map(lambda num:[num[0].replace('(',''),num[1].strip(')').replace('(','')] if len(num)== 2 else [num[0],':'.join(num[1:])] ,[i for i in packet_raw])
    raw = list(packet_raw)[:-1]
    cols = [i[0] for i in raw]
    vals = [i[1] for i in raw]
    temp_array.append(dict(zip(cols,vals)))
    return dict(zip(cols,vals))


def preprocess_dataset(x):
    count = 0
    temp = []
    #print(list(cap))
    #p = Pool(5)
    #r = p.map(parse,cap)
    #p.close()
    #p.join()
    #print(r)
    try:
       for i in list(cap):
          temp.append(parse(i))
          count += 1
    except Exception:
       print("somethin")

    data = pd.DataFrame(temp)
    print(data)
    data = data[['Packet Length','.... 0101 = Header Length','Protocol','Time to Live','Source Port','Length','Time since previous frame in this TCP stream','Window']]
    data.rename(columns={".... 0101 = Header Length": 'Header Length'})
    filtr = ["".join(re.findall(r'\d.',str(i))) for i in data['Time since previous frame in this TCP stream']]
    data['Time since previous frame in this TCP stream'] = filtr
    print(data.to_csv('data.csv'))

我尝试使用 pypy3 c.py 运行脚本 但出现了上述错误, 我安装了 pypy3 -m pip install pyshark 但是...

here i tryied to run script with pypy3 c.py but above error occured ,
i installed pypy3 -m pip install pyshark but ...

pypy3 c.py

ModuleNotFoundError: No module named 'lxml.objectify'

import pyshark
import pandas as pd
import numpy as np
from multiprocessing import Pool
import re
import sys

temp_array  = []

cap = pyshark.FileCapture("ddos_attack.pcap")
#print(cap._extract_packet_json_from_data(cap[0]))

def parse(capture):
    print(capture)
    packet_raw = [i.strip('\r').strip('\t').split(':') for i in str(capture).split('\n')]
    packet_raw = map(lambda num:[num[0].replace('(',''),num[1].strip(')').replace('(','')] if len(num)== 2 else [num[0],':'.join(num[1:])] ,[i for i in packet_raw])
    raw = list(packet_raw)[:-1]
    cols = [i[0] for i in raw]
    vals = [i[1] for i in raw]
    temp_array.append(dict(zip(cols,vals)))
    return dict(zip(cols,vals))


def preprocess_dataset(x):
    count = 0
    temp = []
    #print(list(cap))
    #p = Pool(5)
    #r = p.map(parse,cap)
    #p.close()
    #p.join()
    #print(r)
    try:
       for i in list(cap):
          temp.append(parse(i))
          count += 1
    except Exception:
       print("somethin")

    data = pd.DataFrame(temp)
    print(data)
    data = data[['Packet Length','.... 0101 = Header Length','Protocol','Time to Live','Source Port','Length','Time since previous frame in this TCP stream','Window']]
    data.rename(columns={".... 0101 = Header Length": 'Header Length'})
    filtr = ["".join(re.findall(r'\d.',str(i))) for i in data['Time since previous frame in this TCP stream']]
    data['Time since previous frame in this TCP stream'] = filtr
    print(data.to_csv('data.csv'))

here i tryied to run script with pypy3 c.py
but above error occured ,
i installed pypy3 -m pip install pyshark but ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灯下孤影 2025-01-21 21:06:48
  1. 检查您的终端设置。
  2. 尝试使用其他编译器,例如 PyCharm。
  1. Check your terminal settings.
  2. Try to use another compiler like PyCharm.
嘦怹 2025-01-21 21:06:48

看来 lxml 没有正确安装。很难弄清楚发生了什么,因为您只显示回溯的最后一行,并且没有说明您所在的平台或您正在使用的 PyPy 版本。 lxml 包被列为 pyshark 的要求,因此它应该已经安装了。当您尝试 import lxml 时会发生什么?

It seems lxml is not installed correctly. It is hard to figure out what is going on since you only show the last line of the traceback, and do not state what platform you are on nor what version of PyPy you are using. The lxml package is listed as a requirement for pyshark, so it should have been installed. What happens when you try import lxml ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文