Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pyinstaller:AttributeError:';模块';对象没有属性';RSA&x27;_Python_Rsa_Pyinstaller_Scapy_Attributeerror - Fatal编程技术网

Python pyinstaller:AttributeError:';模块';对象没有属性';RSA&x27;

Python pyinstaller:AttributeError:';模块';对象没有属性';RSA&x27;,python,rsa,pyinstaller,scapy,attributeerror,Python,Rsa,Pyinstaller,Scapy,Attributeerror,我的python文件可以直接与python一起运行: python detectIPConflict.py pyinstaller --onefile detectIPConflict.py ./dist/detectIPConflict WARNING: No route found for IPv6 destination :: (no default route?) Traceback (most recent call last): File "<string>",

我的python文件可以直接与python一起运行:

python detectIPConflict.py
pyinstaller --onefile detectIPConflict.py
./dist/detectIPConflict
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/all.py", line 46, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/crypto/__init__.py", line 17, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/crypto/cert.py", line 19, in <module>
AttributeError: 'module' object has no attribute 'RSA'
detectIPConflict returned -1
from Crypto.PublicKey import *
但是,当PyInstaller打包脚本时:

python detectIPConflict.py
pyinstaller --onefile detectIPConflict.py
./dist/detectIPConflict
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/all.py", line 46, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/crypto/__init__.py", line 17, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/crypto/cert.py", line 19, in <module>
AttributeError: 'module' object has no attribute 'RSA'
detectIPConflict returned -1
from Crypto.PublicKey import *
错误出现了:

python detectIPConflict.py
pyinstaller --onefile detectIPConflict.py
./dist/detectIPConflict
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/all.py", line 46, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/crypto/__init__.py", line 17, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller-3.1.1-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "scapy/crypto/cert.py", line 19, in <module>
AttributeError: 'module' object has no attribute 'RSA'
detectIPConflict returned -1
from Crypto.PublicKey import *
我找不到发生此错误的原因。 我感到困惑。

有人能帮忙吗?

版本信息:

  • Python:2.7.6
  • pyinstaller:3.1.1
  • scapy:2.3.2(由pip命令安装)
  • pycrypto:2.6.1
以下是detectIPConflict.py:

#!/usr/bin/env python
# -*- coding:utf-8 -*-
from scapy.all import *

def ip_conflict():
    ipscan='10.2.86.190/23'
    ip_dict = dict()
    ip_me = get_if_addr('eth0')
    mac_me = get_if_hwaddr('eth0')
    print "--------IP ME---------"
    print ip_me, "--", mac_me
    print "----------------------"
    ip_dict[ip_me] = mac_me
    try:
        ans,unans=srp(Ether(dst="FF:FF:FF:FF:FF:FF")/ARP(pdst=ipscan),iface="br0", timeout=2,verbose=False)
    except Exception,e:
        print str(e)
    else:
        print ("   MAC            --   IP   ")
        for snd,rcv in ans:
            list_mac=rcv.sprintf("%Ether.src% -- %ARP.psrc%")
            mac = rcv.sprintf("%Ether.src%")
            ip = rcv.sprintf("%ARP.psrc%")
            # print mac,'-->',ip
            if ip not in ip_dict:
                ip_dict[ip] = mac
    for has_ip in ip_dict.keys():
        print has_ip, "------ " + ip_dict[has_ip]
if __name__ == "__main__":
    ip_conflict()

我已通过修改python2.7/dist-packages/scapy/crypto/cert.py代码修复了此错误: 修改第19、20、21行:

from Crypto.PublicKey import RSA
from Crypto.Cipher import ARC2
from Crypto.Hash import MD2
这对我有用

然而,我不知道为什么pyinstaller不能识别“import*”。 谢谢你的解释