NaturalHistoryMuseum / pyzbar

Read one-dimensional barcodes and QR codes from Python 2 and 3.
MIT License
718 stars 175 forks source link

FileNotFoundError: Could not find module 'libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.` #161

Open ghost opened 6 months ago

ghost commented 6 months ago

CHECK THE BOLD MESSAGES

I don't know if this is a common prob to everyone and if this will be the longest Issue ever but I'll try to make it short but still providing the error and the codes:

The Error: Traceback (most recent call last): File "d:\OneDrive - De La Salle Santiago Zobel School, Inc\Desktop\FLL\app.py", line 3, in <module> from pyzbar.pyzbar import decode File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\pyzbar.py", line 7, in <module> from .wrapper import ( File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\wrapper.py", line 151, in <module> zbar_version = zbar_function( File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\wrapper.py", line 148, in zbar_function return prototype((fname, load_libzbar())) File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\wrapper.py", line 127, in load_libzbar libzbar, dependencies = zbar_library.load() File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\zbar_library.py", line 61, in load dependencies, libzbar = load_objects(dll_path.parent) File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\zbar_library.py", line 50, in load_objects deps = [ File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\zbar_library.py", line 51, in <listcomp> cdll.LoadLibrary(str(directory.joinpath(dep))) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 452, in LoadLibrary return self._dlltype(name) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\ctypes\__init__.py", line 374, in __init__ self._handle = _dlopen(self._name, mode) FileNotFoundError: Could not find module 'libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.

It's literally told there that the problem is libiconv.dll. I will not show my project because it's literally obvious what the problem was. And yes, the file is not in the incorrect path nor corrupted.

This is the unedited code code from zbar_library.py:

`"""Loads zbar and its dependencies. """ import platform import sys

from ctypes import cdll from ctypes.util import find_library from pathlib import Path

all = ['load']

def _windows_fnames(): """For convenience during development and to aid debugging, the DLL names are specific to the bit depth of interpreter.

This logic has its own function to make testing easier
"""
# 'libzbar-64.dll' and 'libzbar-32.dll' each have a dependent DLL -
# 'libiconv.dll' and 'libiconv-2.dll' respectively.
if sys.maxsize > 2**32:
    # 64-bit
    fname = 'libzbar-64.dll'
    dependencies = ['libiconv.dll']
else:
    # 32-bit
    fname = 'libzbar-32.dll'
    dependencies = ['libiconv-2.dll']

return fname, dependencies

def load(): """Loads the libzar shared library and its dependencies. """ if 'Windows' == platform.system():

Possible scenarios here

    #   1. Run from source, DLLs are in pyzbar directory
    #       cdll.LoadLibrary() imports DLLs in repo root directory
    #   2. Wheel install into CPython installation
    #       cdll.LoadLibrary() imports DLLs in package directory
    #   3. Wheel install into virtualenv
    #       cdll.LoadLibrary() imports DLLs in package directory
    #   4. Frozen
    #       cdll.LoadLibrary() imports DLLs alongside executable
    fname, dependencies = _windows_fnames()

    def load_objects(directory):
        # Load dependencies before loading libzbar dll
        deps = [
            cdll.LoadLibrary(str(directory.joinpath(dep)))
            for dep in dependencies
        ]
        libzbar = cdll.LoadLibrary(str(directory.joinpath(fname)))
        return deps, libzbar

    dll_path = Path(r'C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\libzbar-64.dll')
    try:
        dependencies, libzbar = load_objects(Path(''))
    except OSError:
        dependencies, libzbar = load_objects(Path(__file__).parent)
else:
    # Assume a shared library on the path
    path = find_library('zbar')
    if not path:
        raise ImportError('Unable to find zbar shared library')
    libzbar = cdll.LoadLibrary(path)
    dependencies = []

return libzbar, dependencies`

And this is what I edited in the code: `"""Loads zbar and its dependencies. """ import platform import sys

from ctypes import cdll from ctypes.util import find_library from pathlib import Path

all = ['load']

def _windows_fnames(): """For convenience during development and to aid debugging, the DLL names are specific to the bit depth of interpreter.

This logic has its own function to make testing easier
"""
# 'libzbar-64.dll' and 'libzbar-32.dll' each have a dependent DLL -
# 'libiconv.dll' and 'libiconv-2.dll' respectively.
if sys.maxsize > 2**32:
    # 64-bit
    fname = 'libzbar-64.dll'
    dependencies = ['libiconv.dll']
else:
    # 32-bit
    fname = 'libzbar-32.dll'
    dependencies = ['libiconv-2.dll']

return fname, dependencies

def load(): """Loads the libzar shared library and its dependencies. """ if 'Windows' == platform.system():

Possible scenarios here

    #   1. Run from source, DLLs are in pyzbar directory
    #       cdll.LoadLibrary() imports DLLs in repo root directory
    #   2. Wheel install into CPython installation
    #       cdll.LoadLibrary() imports DLLs in package directory
    #   3. Wheel install into virtualenv
    #       cdll.LoadLibrary() imports DLLs in package directory
    #   4. Frozen
    #       cdll.LoadLibrary() imports DLLs alongside executable
    fname, dependencies = _windows_fnames()

    def load_objects(directory):
        # Load dependencies before loading libzbar dll
        deps = [
            cdll.LoadLibrary(str(directory.joinpath(dep)))
            for dep in dependencies
        ]
        libzbar = cdll.LoadLibrary(str(directory.joinpath(fname)))
        return deps, libzbar

    _//Just added this because I was told to in the error_
    dll_path = Path(r'C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\libzbar-64.dll')
    try:
        dependencies, libzbar = load_objects(dll_path)
    except OSError:
        dependencies, libzbar = load_objects(dll_path.parent)
else:
    # Assume a shared library on the path
    path = find_library('zbar')
    if not path:
        raise ImportError('Unable to find zbar shared library')
    libzbar = cdll.LoadLibrary(path)
    dependencies = []

return libzbar, dependencies

`

This is what error I got now from editing line 59 and 61:

Traceback (most recent call last): File "d:\OneDrive - De La Salle Santiago Zobel School, Inc\Desktop\FLL\app.py", line 3, in from pyzbar.pyzbar import decode File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\pyzbar.py", line 7, in from .wrapper import ( File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\wrapper.py", line 151, in zbar_version = zbar_function( File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\wrapper.py", line 148, in zbar_function return prototype((fname, load_libzbar())) File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\wrapper.py", line 127, in load_libzbar libzbar, dependencies = zbar_library.load() File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\zbar_library.py", line 61, in load dependencies, libzbar = load_objects(dll_path.parent) File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\zbar_library.py", line 50, in load_objects deps = [ File "C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\zbar_library.py", line 51, in cdll.LoadLibrary(str(directory.joinpath(dep))) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64qbz5n2kfra8p0\lib\ctypes__init__.py", line 452, in LoadLibrary return self._dlltype(name) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64qbz5n2kfra8p0\lib\ctypes__init.py", line 374, in init__ self._handle = _dlopen(self._name, mode) FileNotFoundError: Could not find module 'C:\Users\zande\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pyzbar\libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.

Almost the same but I change the code with the constructor syntax now. I have been researching from here in github, in other websites, and still didn't find anything to fix this. Can someone from the devs help me here?

ghost commented 6 months ago

P.S. Also do not include #13 and #73 here. That still did not work. I also tried the opinions from #93 (Because it's similar to that) but still got 0% in the improvement. (btw i know not related to the problem but still concerned me, why is the ones of the issues similar...?)

cosing commented 3 months ago

I just followed stackoverflow and solved it on my computer

  1. down pyzbar-0.1.9-py2.py3-none-win_amd64.whl in https://pypi.org/project/pyzbar/#files
  2. unzip .whl file
  3. move libzbar-64.dll and libiconv.dll to Lib\site-packages\pyzbar\
Iyyappan-vw commented 2 months ago

I just followed stackoverflow and solved it on my computer

down pyzbar-0.1.9-py2.py3-none-win_amd64.whl in https://pypi.org/project/pyzbar/#files unzip .whl file move libzbar-64.dll and libiconv.dll to Lib\site-packages\pyzbar\ I am using same above step but It not solved

ko255128 commented 1 month ago

I just followed stackoverflow and solved it on my computer

down pyzbar-0.1.9-py2.py3-none-win_amd64.whl in https://pypi.org/project/pyzbar/#files unzip .whl file move libzbar-64.dll and libiconv.dll to Lib\site-packages\pyzbar\ I am using same above step but It not solved

I install Visual C++ Redistributable Packages for Visual Studio 2013 and solved it on my computer

Hamidshah09 commented 4 days ago

I install Visual C++ Redistributable Packages for Visual Studio 2013 and solved it on my computer