Search code examples
pythonpython-3.xwindowspyinstaller

Python File Error: unpack requires a buffer of 16 bytes


im trying to use pyinstaller to convert this python file to a exe file, but whenever i try to do this i get an error in the output. Im using cmd with the auto-py-to-exe command and ive been trying to figure out what this error means but i cannot understand a thing about what is going on.

If anyone knows how to fix this, please help. Everything shown is the information I know.

Here is my code:

import os
import string
import colorama
from colorama import Fore, Back, Style, init
import shutil
import getpass
import time
from time import sleep

available_drives = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]

init()
username = getpass.getuser()

driveLetter = None
driveFiles = None
fileDest = None


def getDrive():
    global driveLetter
    global driveFiles
    global fileDest
    print(Fore.CYAN + "Select the drive to organize")
    print(Fore.YELLOW + str(available_drives))
    print(Fore.RESET)
    driveLetter = input("USB Drive Letter: ")
    os.mkdir("C:\\Users\\" + username + "\\Desktop\\Organized Files")
    fileDest = "C:\\Users\\" + username + "\\Desktop\\Organized Files"
    driveFiles = driveLetter + "\\"
    checkDrive()

def checkDrive():
    if os.path.exists(driveLetter + "\\"):
        textPopup()
    else:
        print(Fore.RED + "Error: " + Fore.YELLOW + "Required folder does not exist on drive")
        print(Fore.RESET)
        print()
        getDrive()

def textPopup():
    print()
    print()
    print(Fore.YELLOW + "This makes a folder on the Desktop called 'Organized Files', your Files will be put in there")
    time.sleep(3)
    makeFolders()


def makeFolders():
    for path, dir, files in os.walk(driveFiles):
        for file in files:
            filename, fileExtension = os.path.splitext(file)
            if not os.path.exists(fileDest + "\\" + fileExtension):
                try:
                    os.mkdir("C:\\Users\\" + username + "\\Desktop\\Organized Files\\" + fileExtension)
                    print(Fore.GREEN + "Created Folder: " + Fore.WHITE + fileExtension)
                except OSError:
                    print(Fore.RED + "Error: " + Fore.YELLOW + "Unable to Create Folder")
                    pass
            else:
                pass
    organize()

unableToCopyErrors = 0
renamedFileCount = 0
sameCount = 0

def organize():
    global unableToCopyErrors
    global renamedFileCount
    global sameCount
    for path, dir, files in os.walk(driveFiles):
        for file in files:
            filename, fileExtension = os.path.splitext(file)
            print(Fore.YELLOW + "Copying File: " + Fore.WHITE + file)
            try:
                shutil.copy2(path + "\\" + file, fileDest + "\\" + fileExtension + "\\" + file)
                fullFilePath = fileDest + "\\" + fileExtension + "\\" + file
            except OSError:
                print(Fore.RED + "Error: Unable To Copy")
                unableToCopyErrors += 1
                pass
            if os.path.isfile(fullFilePath):
                print(Fore.GREEN + "File Copied")
            else:
                print(Fore.RED + "Error: Unable To Copy")
                unableToCopyErrors += 1
    complete()

count = 0

def complete(): 
    global count
    for path, dir, files in os.walk(fileDest):
        for file in files:
            count += 1
    print()
    print()
    print(Fore.RESET)
    print(Fore.CYAN + Style.BRIGHT + "Copying Completed.")
    print(Fore.RESET)
    print("Copied Files Count: " + Fore.YELLOW + str(count))
    print(Fore.RESET)
    print("Unable to Copy Errors: " + Fore.YELLOW + str(unableToCopyErrors))
    print(Fore.RESET)
    print()
    print()
    input(Fore.MAGENTA + "Press ENTER to Exit...")
    exit()

getDrive()

Here is the output:

Running auto-py-to-exe v2.7.11
Building directory: C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv
Provided command: pyinstaller --noconfirm --onefile --console --icon "C:/Users/Sean/Desktop/Misc/Icons/Dort.ico"  "C:/Users/Sean/Desktop/Programs/Python/Dort/Data/Dort.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onefile --console --icon C:/Users/Sean/Desktop/Misc/Icons/Dort.ico C:/Users/Sean/Desktop/Programs/Python/Dort/Data/Dort.py --distpath C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\application --workpath C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\build --specpath C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv

24992 INFO: PyInstaller: 4.2.dev0
25005 INFO: Python: 3.9.2
25006 INFO: Platform: Windows-10-10.0.19041-SP0
25021 INFO: wrote C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\Dort.spec
25038 INFO: UPX is not available.
25056 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Sean\\Desktop\\Programs\\Python\\Dort\\Data',
 'C:\\Users\\Sean\\AppData\\Local\\Temp\\tmp8dnehxpv']
25072 INFO: checking Analysis
25083 INFO: Building Analysis because Analysis-00.toc is non existent
25098 INFO: Initializing module dependency graph...
25114 INFO: Caching module graph hooks...
25132 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
25146 INFO: Analyzing base_library.zip ...
26527 INFO: Processing pre-find module path hook distutils from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
26535 INFO: distutils: retargeting to non-venv dir 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib'
28250 INFO: Caching module dependency graph...
28316 INFO: running Analysis Analysis-00.toc
28328 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\sean\appdata\local\programs\python\python39\python.exe
28363 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of c:\users\sean\appdata\local\programs\python\python39\python39.dll
28386 INFO: Analyzing C:\Users\Sean\Desktop\Programs\Python\Dort\Data\Dort.py
28421 INFO: Processing module hooks...
28425 INFO: Loading module hook 'hook-difflib.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28442 INFO: Excluding import of doctest from module difflib
28443 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28458 INFO: Loading module hook 'hook-distutils.util.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28473 INFO: Excluding import of lib2to3.refactor from module distutils.util
28487 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28536 INFO: Loading module hook 'hook-heapq.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28550 INFO: Excluding import of doctest from module heapq
28565 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28584 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28596 INFO: Excluding import of test.support from module multiprocessing.util
28597 INFO: Excluding import of test from module multiprocessing.util
28611 INFO: Loading module hook 'hook-pickle.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28613 INFO: Excluding import of argparse from module pickle
28627 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28629 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28643 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28690 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks'...
28803 INFO: checking Tree
28814 INFO: Building Tree because Tree-00.toc is non existent
28830 INFO: Building Tree Tree-00.toc
28882 INFO: checking Tree
28894 INFO: Building Tree because Tree-01.toc is non existent
28910 INFO: Building Tree Tree-01.toc
28976 INFO: checking Tree
28990 INFO: Building Tree because Tree-02.toc is non existent
28991 INFO: Building Tree Tree-02.toc
29012 INFO: Looking for ctypes DLLs
29038 INFO: Analyzing run-time hooks ...
29052 INFO: Including run-time hook 'c:\\users\\sean\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
29071 INFO: Looking for dynamic libraries
29241 INFO: Looking for eggs
29243 INFO: Using Python library c:\users\sean\appdata\local\programs\python\python39\python39.dll
29245 INFO: Found binding redirects: 
[]
29249 INFO: Warnings written to C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\build\Dort\warn-Dort.txt
29285 INFO: Graph cross-reference written to C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\build\Dort\xref-Dort.html
29306 INFO: checking PYZ
29315 INFO: Building PYZ because PYZ-00.toc is non existent
29331 INFO: Building PYZ (ZlibArchive) C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\build\Dort\PYZ-00.pyz
29655 INFO: Building PYZ (ZlibArchive) C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\build\Dort\PYZ-00.pyz completed successfully.
29664 INFO: checking PKG
29666 INFO: Building PKG because PKG-00.toc is non existent
29670 INFO: Building PKG (CArchive) PKG-00.pkg
30774 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
30793 INFO: Bootloader c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
30808 INFO: checking EXE
30823 INFO: Building EXE because EXE-00.toc is non existent
30839 INFO: Building EXE from EXE-00.toc
30855 INFO: Copying icons from ['C:\\Users\\Sean\\Desktop\\Misc\\Icons\\Dort.ico']
An error occurred while packaging
Traceback (most recent call last):
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\auto_py_to_exe\packaging.py", line 131, in package
    run_pyinstaller()
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 725, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 672, in build
    exec(code, spec_namespace)
  File "C:\Users\Sean\AppData\Local\Temp\tmp8dnehxpv\Dort.spec", line 20, in <module>
    exe = EXE(pyz,
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\api.py", line 450, in __init__
    self.__postinit__()
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\api.py", line 550, in assemble
    icon.CopyIcons(tmpnm, self.icon)
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\win32\icon.py", line 216, in CopyIcons
    return CopyIcons_FromIco(dstpath, [srcpath])
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\win32\icon.py", line 153, in CopyIcons_FromIco
    for i, f in enumerate(icons):
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\win32\icon.py", line 117, in __init__
    entry.fromfile(file)
  File "c:\users\sean\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\win32\icon.py", line 76, in fromfile
    self._fields_ = list(struct.unpack(self._format_, data))
struct.error: unpack requires a buffer of 16 bytes

Project output will not be moved to output folder
Complete.

The command im using is:

pyinstaller --noconfirm --onefile --console --icon "C:/Users/Sean/Desktop/Misc/Icons/Dort.ico"

Solution

  • The icon for your program needs to be a valid .ico file; it can't be just a renamed .png for instance. Source: this post I found when googling the error.