Search code examples
pythonpandasutf-8pyinstallerjupyter-lab

Pyinstaller - Failed to decode wchar_t from UTF-8 (fopen: no such file or directory)


So I have looked around at a lot of answers on SO, and I can't seem to wrap my head around what is possibly going on. After having used pyinstaller to create an exe (and moved it to the directory with the dependencies), I get this obscure error:

Failed to decode wchar_t from UTF-8
MultiByteToWideChar: The data area passed to a system call is too small.
share\jupyter\lab\staging\node_modules\.cache\terser-webpack-plugin\content-v2\sha512\2e\ba\cfce62ec1f408830c0335f2b46219d58ee5b068473e7328690e542d2f92f2058865c600d845a2e404e282645529eb0322aa4429a84e189eb6b58c1b97c1a could not be extracted!
fopen: No such file or directory 

There is only one file dependency here which is the invoice file when the historical sales are defined (not sure if using an absolute string is what is causing the problem here). I don't recall decoding anything either so I am quite confused as to how to fix this error (I also don't know what jupyter lab has to do with my python script - it was originally converted from a notebook, but I wouldn't have thought that would have mattered).

The code I compiled is below (I have intentionally removed the cnxn details for security reasons, but the code executes fine in any of the IDEs). Forgive me for the code being a bit sloppy (I'm a noob):

#!/usr/bin/env python
# coding: utf-8
running = True

# 2376 is a valid order number

while running:
    import pandas as pd
    
    import pyodbc 
    cnxn = pyodbc.connect("")
    
    
    pd.set_option('display.max_columns', None)
    
    design = ""
    order = ""

    while True:
        design_or_order = input("Do you wish to check an individual design (D) or an order (O): ")
        if design_or_order not in ["D","O"]:
            print("Type either an O or a D")
        else:
            break

    if design_or_order == "D":
        
        customers = pd.read_sql_query('select ACCOUNT from CUSTOMER', cnxn).convert_dtypes()
        customers = customers.ACCOUNT.to_list()

        inventory = pd.read_sql_query("select DESIGN from STCKHEAD", cnxn).convert_dtypes()            
        inventory = inventory.DESIGN.to_list()
        
        while True:
            account = input("Enter Account Code:")

            if account not in customers:
                print("Please enter a valid account code")
            else:
                break
        while True:
            design = [input("Enter Design Code:")]
            if design[0] not in inventory:
                print("Please enter a valid design code")
            else:
                break

    else:
        process_orders = pd.read_sql_query("select ORDERNUM from OrderExportView where STAGE = 'B'", cnxn).convert_dtypes()
        process_orders = process_orders.ORDERNUM.to_list()
        #print(process_orders)
        
        while True:
            try:
                order = int(input("Enter Order Number:"))
            except ValueError:
                print ("Please enter an Integer")
            else:
                if order not in process_orders:
                    print("Please enter a valid (scan pack) order number")
                else:
                    break

Solution

  • Solved it.

    Basically looked the log file and realised I just needed to do

    pyinstaller --exclude-module IPython --onefile "filename"
    

    to get it to work (Pandas was bringing in IPython which was bringing in jupyter labs which was causing problems).

    This SO question helped me: Pyinstaller failed to import scipy.signals