2016-02-18 31 views
5

我的Python文件運行良好的Python直接:pyinstaller:AttributeError的: '模塊' 對象有沒有屬性 'RSA'

python detectIPConflict.py 

然而,當PyInstaller包裝腳本:

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 

我也有尋求到Scapy的/密碼/ cert.py,在第19行:

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() 

回答

3

我已經在python2.7/DIST-包/ Scapy的/密碼/ cert.py代碼的修改解決了這個錯誤: 修改行19,20,21:

from Crypto.PublicKey import RSA 
from Crypto.Cipher import ARC2 
from Crypto.Hash import MD2 

這對我的作品。

但是,我不知道爲什麼'import *'不能被pyinstaller識別。 感謝fort任何解釋。

相關問題