Getting winerror 3 filenotfounderror in basicsr\\archs after generating exe file by pyinstaller in python

481 Views Asked by At

I'm using BasicSR in my one of the desktop application. and It's working and running fine on PyCharm.

But after converting it to EXE file using pyinstaller, I'm getting below error.

I think it can be os.scandir, but how can I solve this, I don't know..

please help me to resolve this as I've already spent a lot time..

Traceback (most recent call last):
File "yogeshbhaiDesktop.py", line 7, in
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "basicsr_init.py", line 3, in
File "", line 991, in _find_and_load
File "", line 975, in find_and_load_unlocked
File "", line 671, in load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
File "basicsr\archs_init.py", line 14, in
File "basicsr\archs_init.py", line 14, in
File "basicsr\utils\misc.py", line 74, in _scandir
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\Users\gbd\AppData\Local\Temp\_MEI45162\basicsr\archs'

.spec file:

# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(['yogeshbhaiDesktop.py'],
             pathex=['E:\\deployyPythonDesktop'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=['hook-basicsr.py'],
             hooksconfig={},
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,  
          [],
          name='yogeshbhaiDesktop',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=False,
          disable_windowed_traceback=False,
          target_arch=None,
          codesign_identity=None,
          entitlements_file=None )

hook-basicsr.py file

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files("basicsr", includes=["archs/*_arch.py"])

Thanks in advance..

1

There are 1 best solutions below

0
dogegg On

I solved this problem by replacing the content of basicsr/archs/__init__.py with the following. And do the same operation for those who use scandir in __init__.py.

import importlib
from copy import deepcopy
from os import path as osp

from basicsr.utils import get_root_logger, scandir
from basicsr.utils.registry import ARCH_REGISTRY

__all__ = ['build_network']

# automatically scan and import arch modules for registry
# scan all the files under the 'archs' folder and collect files ending with
# '_arch.py'
# arch_folder = osp.dirname(osp.abspath(__file__))
# arch_filenames = [osp.splitext(osp.basename(v))[0] for v in scandir(arch_folder) if v.endswith('_arch.py')]
# # import all the arch modules
# _arch_modules = [importlib.import_module(f'basicsr.archs.{file_name}') for file_name in arch_filenames]

from . import basicvsrpp_arch
from . import basicvsr_arch
from . import dfdnet_arch
from . import discriminator_arch
from . import duf_arch
from . import ecbsr_arch
from . import edsr_arch
from . import edvr_arch
from . import hifacegan_arch
from . import rcan_arch
from . import ridnet_arch
from . import rrdbnet_arch
from . import spynet_arch
from . import srresnet_arch
from . import srvgg_arch
from . import stylegan2_arch
from . import swinir_arch
from . import tof_arch
from . import vgg_arch

def build_network(opt):
    opt = deepcopy(opt)
    network_type = opt.pop('type')
    net = ARCH_REGISTRY.get(network_type)(**opt)
    logger = get_root_logger()
    logger.info(f'Network [{net.__class__.__name__}] is created.')
    return net