编译 - OsError:无法加载本机模块' Cryptodome.Cipher._raw_ecb'

时间:2016-09-13 10:32:12

标签: python compiler-errors cx-freeze pycrypto

from pubnub import Pubnub ; 
from tkinter import *

Window = Tk()
pubnub = Pubnub(publish_key="pub-c-9997b5b1-da6f-4935-88f7-4d0645bcdf2b", 
    subscribe_key="sub-c-2bc2a578-776c-11e6-9195-02ee2ddab7fe")

def Callback(message, channel):
    Logic.UpdateMessageList(message)
    Logic.UpdateMessageDisplay()
    Display.DisplayMessage()

def Error(message):
    Window.title("PubNub - Error")

def Connect(message):
    Window.title("PubNub - Connected")

def Reconnect(message):
    Window.title("PubNub - Reconnected")

def Disconnect(message):
    Window.title("PubNub - Disconnected")

def SendMessage(event):
    message = (Logic.Username, Display.MessageEntry.get())
    pubnub.publish("my_channel", message =  message)

pubnub.subscribe(channels='my_channel',
                         callback =  Callback,
                         error = Error,
                         connect = Connect,
                         reconnect = Reconnect,
                         disconnect = Disconnect)

class Logic:
    def __init__(self):
        self.Username = ""
        self.MessageList = ([],[])
        self.MessageNumber = 0
        self.MaxMessages = 6

    def UpdateMessageList(self, message):
        self.MessageList[0].append(message[0])
        self.MessageList[1].append(message[1])
        self.MessageNumber += 1

    def UpdateMessageDisplay(self):
        self.DisplayList = []
        if self.MessageNumber >= (self.MaxMessages + 1):
            self.MessageList[0].pop(0)
            self.MessageList[1].pop(0)

        for Num in range(len(self.MessageList[0])):
            for ListNum in range(2):
               self.DisplayList.append((self.MessageList[ListNum][Num]))
               self.DisplayList.append("\n")

Logic = Logic()

class MainDisplay:
    def __init__(self):
        Window.geometry("400x400")
        Window.resizable(0,0)
        self.MessageVar = StringVar()
        Window.title("PubNub")

def ScreenOne(self):
    Window.bind("<Return>", self.AdvScreenTwo)

    self.EasyFrame = Frame(Window)
    self.EasyFrame.config(bg = "Grey", height = 400, width = 400)
    self.EasyFrame.grid()
    self.EasyFrame.place(relx = 0.5, y = 200, anchor = CENTER)

    self.UsernameEntry = Entry(self.EasyFrame)
    self.UsernameEntry.config(width = 15, bg = "White", fg = "Black")
    self.UsernameEntry.grid()
    self.UsernameEntry.place(relx = 0.5, y = 200, anchor = CENTER)

    UsernameLabel = Label(self.EasyFrame, text = "Enter Username")
    UsernameLabel.config(bg = "Grey", bd = 0, font = ("times",13,"bold"), fg = "White")
    UsernameLabel.grid()
    UsernameLabel.place(relx = 0.5, y = 90, anchor = CENTER)

def AdvScreenTwo(self, event):
    Logic.Username = (self.UsernameEntry.get())
    Window.unbind("<Return>")
    self.EasyFrame.grid_forget()
    self.EasyFrame.destroy()
    Window.bind("<Return>", SendMessage)
    self.ScreenTwo()

def ScreenTwo(self):
    self.MessagesParent = Frame(Window)
    self.MessagesParent.config(bg = "Grey", height = 400, width = 400)
    self.MessagesParent.grid()
    self.MessagesParent.place(relx = 0.5, y = 200, anchor = CENTER)

    self.MessageEntry = Entry(self.MessagesParent)
    self.MessageEntry.config(width = 40, bg = "Grey", fg = "Black")
    self.MessageEntry.grid()
    self.MessageEntry.place(relx = 0.5, y = 350, anchor = CENTER)

def DisplayMessage(self):
    Y = 10
    for Item in (Logic.MessageList[0]):
        self.TextLabel = Label(Window, text = Item, height = 3, width = 6, font = ("times", 8, "bold"), anchor = "w")
        self.TextLabel.grid()
        self.TextLabel.place(relx = 0.05, y = Y)
        Y += 50
    Y = 10
    for Item in (Logic.MessageList[1]):
        self.TextLabel = Label(Window, text = Item, height = 3, width = 40, font = ("times", 8, "bold"),wraplength = 270, anchor = "w")
        self.TextLabel.grid()
        self.TextLabel.place(relx = 0.2, y = Y)
        Y += 50

Display = MainDisplay()

def Main():
    Display.ScreenOne()

if __name__ == "__main__":
    Main()

Window.mainloop()

当我通过控制台或IDLE运行时,这是我的代码工作,这很好,但我想编译它。我设法使用 cx_freeze 使用我常用的方法编译它,但是我收到一条错误消息:

OsError: Cannot load native module 'Cryptodome.Cipher,_raw_ecb'

可以提供可能需要的任何其他信息。

1 个答案:

答案 0 :(得分:0)

已经获得了相当多的观点,所以我想我会发布答案,我通过电子邮件发送pubnub支持

Hi Joshua,

Please use this branch from our SDK https://github.com/pubnub/python/tree/reduce_crypto ; it has cryto unbundled from the dependencies.

这修复了它:)(用git上的pubnub.py文件替换Pythonx.x中的pubnub文件)