文件未找到错误:无法找到模块'C:\Users\(路径...)\site-packages\pyzbar\libzbar-64.dll'(或其依赖项之一)。

3
我遇到了一个错误:FileNotFoundError: 找不到模块 'C:\Users(path...)\pythonProject\venv\lib\site-packages\pyzbar\libzbar-64.dll'(或其依赖项之一)。尝试使用构造函数语法提供完整路径。但是,正如您在screenshot中所看到的,libzbar-64.dll 存储在上述指定位置。 下面是代码,它应该是一个使用 tkinter 的 QR 码应用程序。
from tkinter import *
from tkinter import ttk
from tkinter import filedialog

from PIL import Image, ImageTk
from pyzbar.pyzbar import decode
import pyqrcode
import os

root = Tk()
root.title("QR code application")
note = ttk.Notebook(root)
note.pack()
# create frames to add on tabs
frame1 = Frame(note, height=400, width=150, bg='white')
frame1.pack(fill="both", expand=True)
frame2 = Frame(note, height=400, width=150, bg='white')
frame2.pack(fill="both", expand=True)
s = ttk.Style()
s.theme_create("style", parent="alt", settings={
    "TNotebook.Tab": {"configure": {"padding": [20, 10],
                                    "font": ('Times', '20', 'bold')}}})
s.theme_use("style")
# add tabs
note.add(frame1, text="Generate QR Code")
note.add(frame2, text="Read QR Code")
# create canvas to display image
canvas1 = Canvas(frame1, width="400", height="300", relief=RIDGE, bd=2)
canvas1.pack(padx=10, pady=10)
canvas2 = Canvas(frame2, width="400", height="400", relief=RIDGE, bd=2)
canvas2.pack(padx=10, pady=10)


def generate():
    if data_entry.get() != '' and save_entry.get() != '':
        qr = pyqrcode.create(data_entry.get())
        img = qr.png(save_entry.get() + ".png", scale=5)
        info = Label(frame1, text="Generated QR code:", font=('ariel 15 bold'))
        info.place(x=60, y=40)
        img = Image.open(save_entry.get() + ".png")
        img = ImageTk.PhotoImage(img)
        canvas1.create_image(200, 180, image=img)
        canvas1.image = img
    else:
        info = Label(frame1, text="Please enter the data for QR code", font=('ariel 15 bold'))
        info.place(x=80, y=140)


def selected():
    img_path = filedialog.askopenfilename(initialdir=os.getcwd(),
                                          title="Select Image", filetype=(
            ("PNG file", "*.png"), ("All files", "*.*")))
    img = Image.open(img_path)
    img = ImageTk.PhotoImage(img)
    canvas2.create_image(200, 190, image=img)
    canvas2.image = img
    d = decode(Image.open(img_path))
    data = d[0].data.decode()
    qrcode_data = Label(frame2, text=data, bg='gold', fg='black', font=('ariel 15 bold'), relief=GROOVE)
    qrcode_data.place(x=150, y=380)


data_label = Label(frame1, text='Enter data:', font=('ariel 15 bold'), bg='white')
data_label.place(x=61, y=330)
save_label = Label(frame1, text='Enter name \n to save with:', font=('ariel 15 bold'), bg='white')
save_label.place(x=55, y=360)
data_entry = Entry(frame1, font=('ariel 15 bold'), relief=GROOVE, bd=3)
data_entry.place(x=197, y=330)
save_entry = Entry(frame1, font=('ariel 15 bold'), relief=GROOVE, bd=3)
save_entry.place(x=197, y=380)
btn1 = Button(frame1, text="Generate", bg='black', fg='gold', font=('ariel 15 bold'), relief=GROOVE, command=generate)
btn1.place(x=85, y=425)
btn2 = Button(frame1, text="Exit", width=10, bg='black', fg='gold', font=('ariel 15 bold'), relief=GROOVE,
              command=root.destroy)
btn2.place(x=255, y=425)
btn2 = Button(frame2, text="Select Image", bg='black', fg='gold', font=('ariel 15 bold'), relief=GROOVE,
              command=selected)
btn2.pack(side=LEFT, padx=50, pady=5)
btn3 = Button(frame2, text="Exit", width=12, bg='black', fg='gold', font=('ariel 15 bold'), relief=GROOVE,
              command=root.destroy)
btn3.pack(side=LEFT, padx=10, pady=5)
root.mainloop()

这与tkinter、QR码或解码器有什么关系? - Matiiss
无法在我的PyCharm环境中重现该错误。 - acw1668
我哪里出错了呢? - Akash Sharma
4个回答

1
同样的错误。在Pypi页面上阅读,他们说在Windows上出现ImportError的情况下,我们应该安装“Visual C++ Redistributable Package per Visual Studio 2013”。我这样做了,然后就可以工作了!请参见https://pypi.org/project/pyzbar/,查看“Windows Import Error”。

我得到了最新版本的Visual C++可再发行程序包,它是否会改变事情或是关于特定版本......另外,我仍然无法使用pyzbar。 - Akash Sharma
就像我说的那样,我安装了特定版本,如pypi所解释的那样,并且工作正常。 我不知道它是否适用于其他版本。 - barbax7

0

我遇到了同样的问题,尝试更改Python和PyCharm版本,但仍然无法解决。现在我使用的是python3.9.7和PyCharm2020.2.5。

我的错误提示是“FileNotFoundError: Could not find module 'D:\python3.9.7\Lib\site-packages\PySmartCard\ReaderLib_64.dll'(或其某个依赖项)。尝试使用构造函数语法的完整路径。”

奇怪的是,我在文件路径中有这个.dll文件。


1
这并没有真正回答问题。如果您有不同的问题,可以通过点击提问来提出。如果您想在此问题获得新的答案时收到通知,可以关注此问题。一旦您拥有足够的声望,您还可以添加悬赏以吸引更多关注。- 来自审核 - Gino Mempin
你解决了问题吗? - Calvin_Z

0

您是要导入libzbar或pyzbar吗? 如果您正在尝试导入pyzbar,似乎pyzbar并不在网站包中。

首先尝试安装pip install pyzbar


要求已满足:pyzbar已经在c:\users\new user.laptop-5glt5pl6\pycharmprojects\pythonproject\venv\lib\site-packages (0.1.8)中存在。 - Akash Sharma
尝试将pyzbar作为pyzbar导入,而不是pyzbar.pzybar - MakeTheErrorDie

0

虽然这个链接可能回答了问题,但最好在此处包含答案的基本部分并提供参考链接。如果链接页面更改,仅有链接的答案可能会失效。-【来自审查】 - LSeu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接