繁体   English   中英

错误:没有名为“ mysql”的模块

[英]Error: No module named 'mysql'

我正在做一个需要创建python gui并使用c函数的项目。 我已经尝试安装mysql-python,但没有用。 我正在使用python3.4,xubuntu 16.04。 请告诉我可能是什么问题?

from ctypes import *
# Simple enough, just import everything from tkinter.
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
import subprocess
# Here, we are creating our class, Window, and inheriting from the Frame
# class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__)
import mysql.connector

cnx = mysql.connector.connect(user='root', password='root',
                          host='127.0.0.1',
                          database='iCalender')
cnx.close()

cal = CDLL('./caltool.so')
class Window(Frame):

# Define settings upon initialization. Here you can specify
def __init__(self, master=None):

    # parameters that you want to send through the Frame class.
    Frame.__init__(self, master)
    fm = Frame(root, width=400, height=300, bg="green")
    fm.pack(side=TOP, expand=NO, fill=NONE)
    #reference to the master widget, which is the tk window
    self.master = master

    #with that, we want to then run init_window, which doesn't yet exist
    self.init_window()

#Creation of init_window
def init_window(self):

    # changing the title of our master widget
    self.master.title("XCal Application")

    # allowing the widget to take the full space of the root window
    self.pack(fill=BOTH, expand=1)

    # creating a menu instance
    menu = Menu(self.master)
    self.master.config(menu=menu)

    # create the file object)
    file = Menu(menu)

    # adds a command to the menu option, calling it exit, and the
    # command it runs on event is client_exit
    file.add_command(label="Open", command=self.OpenFile, accelerator="Ctrl+O")
    file.add_command(label="Save", command=self.file_save, accelerator="Ctrl+S")
    file.add_command(label="Save As...", command=self.client_exit, accelerator="Ctrl+Shift+S")
    file.add_command(label="Combine", command=self.client_exit)
    file.add_command(label="Filter", command=self.client_exit)
    file.add_command(label="Exit", command=self.client_exit, accelerator="Ctrl+X")
    self.bind_all("<Control-x>", self.client_exit)
    self.bind_all("<Control-o>", self.OpenFile)
    self.bind_all("<Control-s>", self.file_save)

    #added "file" to our menu
    menu.add_cascade(label="File", menu=file)

    # create the file object)
    edit = Menu(menu)

    # adds a command to the menu option, calling it exit, and the
    # command it runs on event is client_exit
    edit.add_command(label="To Do List", accelerator="Ctrl+T")
    edit.add_command(label="Undo", accelerator="Ctrl+Z")

    #added "file" to our menu
    menu.add_cascade(label="Todo", menu=edit)
    help1 = Menu(menu)
    help1.add_command(label="Date Mask")
    help1.add_command(label="About xcal")
    menu.add_cascade(label="Help", menu=help1)


def client_exit(self, event):
    exit()
def OpenFile(self):
    filename = askopenfilename()
    print(filename)
    cal.pyGetInfo(filename)
def file_save(self, event):
    name = asksaveasfile(mode='w',defaultextension=".txt")
    text2save=str(text.get(0.0,END))
    name.write(text2save)
    name.close


# root window created. Here, that would be the only window, but
# you can later have windows within windows.
root = Tk()

root.geometry("400x300")

#creation of an instance
app = Window(root)

#mainloop
root.mainloop()

Python版本可能会造成混淆,特别是如果您使用apt安装。 mysql-python是python 2软件包。 您可能要安装这个

sudo apt-get install python3-mysql.connector

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM