admin管理员组

文章数量:1386798

I am building an onefile exe using pyinstaller with my python file.

my testing.py file contains following code:


import pandas as pd
import swifter

file = "D:/Testing/file1.csv"

if __name__ == '__main__':
    
    try:
        df = pd.read_csv(file)
        print(df)
        
    except Exception as e:
        print(str(e))
        print(str(repr(e)))

I know in the above sample code I am importing swifter not using it. In my actual code I am using it. This code is to reproduce the error only.

I have used following command to build my exe file using pyinstaller. which created the exe as expected.

pyinstaller --onefile testing.py

When I execute the testing.exe file I got the following error.


Traceback (most recent call last):
  File "testing.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "swifter\__init__.py", line 5, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "swifter\swifter.py", line 13, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "swifter\base.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "numba\__init__.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "numba\core\config.py", line 15, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "llvmlite\binding\__init__.py", line 4, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "llvmlite\binding\dylib.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 450, in exec_module
  File "llvmlite\binding\ffi.py", line 162, in <module>
  File "os.py", line 1111, in add_dll_directory
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'D:\\Users\\username\\AppData\\Local\\Temp\\_MEI82602\\Library\\bin'
[PYI-23332:ERROR] Failed to execute script 'testing' due to unhandled exception!

As suggested in other blogs/posts, I have updated the testing.spec file with required information as below.

# -*- mode: python ; coding: utf-8 -*-
import sys
sys.setrecursionlimit(20000)

a = Analysis(
    ['testing.py'],
    pathex=['D:\\Users\\username\\Anaconda3\\Lib\\site-packages\\swifter'],
    binaries=[],
    datas=[],
    hiddenimports=['swifter','dask','numba','tqdm','modin','ray','llvmlite'],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)
pyz = PYZ(a.pure)

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

using this updated spec file I have rebuit the exe file using the following command.

pyinstaller testing.spec

Which built an exe but getting the same error.

If I remove the import swifter the exe file is working fine.

本文标签: pythonswifter module causing my executable to fail which built by pyinstallerStack Overflow