pythontkinterpyinstallertix

Generating .exe file from Python code that uses Tix


Recently I found a program's code that I used a lot (Pikasav) on Github and since I had recently learned Python syntax, decided to fork it to practice Python and implement some features that would make it easier/better to use.

After implementing a feature, I tried to generate an .exe file using py2exe and it didn't work because it couldn't find the Tix module. I tried copying Tix.py into my working directory, it also didn't work.

After that, I decided to try PyInstaller out, since I thought I was doing something wrong passing arguments to py2exe in the setup.py file, and it seemed much easier to use. However, it also didn't work, because of the same reason, which clearly means the problem is not from py2exe configuration.

Here's the PyInstaller output, although I don't think it will be that useful:

C:\Users\Afonso\Documents\Side Projects\PikaSav>PyInstaller --onefile pikasav.py
1421 INFO: PyInstaller: 3.1.1
1421 INFO: Python: 2.7.11
1421 INFO: Platform: Windows-10-10.0.10240
1421 INFO: wrote C:\Users\Afonso\Documents\Side Projects\PikaSav\pikasav.spec
1421 INFO: UPX is not available.
1437 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Afonso\\Documents\\Side Projects\\PikaSav',
 'C:\\Users\\Afonso\\Documents\\Side Projects\\PikaSav']
1437 INFO: checking Analysis
1437 INFO: Building Analysis because out00-Analysis.toc is non existent
1437 INFO: Initializing module dependency graph...
1452 INFO: Initializing module graph hooks...
1530 INFO: running Analysis out00-Analysis.toc
1657 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
  required by C:\Python27\python.exe
1780 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_60a5df56e60dc5df.manifest
1796 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest
1796 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_f47f259ef656232a.manifest
1873 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.9158_none ...
1873 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc.manifest
1889 INFO: Searching for file msvcr90.dll
1889 INFO: Found file C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcr90.dll
1889 INFO: Searching for file msvcp90.dll
1889 INFO: Found file C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcp90.dll
1889 INFO: Searching for file msvcm90.dll
1889 INFO: Found file C:\WINDOWS\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_5091b51ebcb97cdc\msvcm90.dll
1967 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_60a5df56e60dc5df.manifest
1967 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest
1967 INFO: Found C:\WINDOWS\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9158_none_f47f259ef656232a.manifest
1967 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9158)
2514 INFO: Analyzing C:\Users\Afonso\Documents\Side Projects\PikaSav\pikasav.py
4889 INFO: Looking for import hooks ...
4905 INFO: Processing hook   hook-_tkinter.py
5077 INFO: checking Tree
5077 INFO: Building Tree because out00-Tree.toc is non existent
5092 INFO: Building Tree out00-Tree.toc
5338 INFO: checking Tree
5338 INFO: Building Tree because out01-Tree.toc is non existent
5339 INFO: Building Tree out01-Tree.toc
5389 INFO: Processing hook   hook-encodings.py
7202 INFO: Looking for ctypes DLLs
7202 INFO: Analyzing run-time hooks ...
7202 INFO: Including run-time hook 'pyi_rth__tkinter.py'
7217 INFO: Looking for dynamic libraries
7530 INFO: Looking for eggs
7530 INFO: Using Python library C:\WINDOWS\system32\python27.dll
7530 INFO: Found binding redirects:
[BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'x86', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 9158), publicKeyToken=u'1fc8b3b9a1e18e3b')]
7546 INFO: Warnings written to C:\Users\Afonso\Documents\Side Projects\PikaSav\build\pikasav\warnpikasav.txt
7827 INFO: checking PYZ
7827 INFO: Building PYZ because out00-PYZ.toc is non existent
7827 INFO: Building PYZ (ZlibArchive) C:\Users\Afonso\Documents\Side Projects\PikaSav\build\pikasav\out00-PYZ.pyz
8062 INFO: checking PKG
8062 INFO: Building PKG because out00-PKG.toc is non existent
8062 INFO: Building PKG (CArchive) out00-PKG.pkg
8280 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9158)
16608 INFO: Bootloader C:\Python27\lib\site-packages\pyinstaller-3.1.1-py2.7.egg\PyInstaller\bootloader\Windows-32bit\run.exe
16608 INFO: checking EXE
16608 INFO: Building EXE because out00-EXE.toc is non existent
16608 INFO: Building EXE from out00-EXE.toc
16702 INFO: Appending archive to EXE C:\Users\Afonso\Documents\Side Projects\PikaSav\dist\pikasav.exe

And here's the warnpikasav.txt content, which is mentioned in the output above.

missing module named unicodedata.ucd_3_2_0 - imported by unicodedata, stringprep, encodings.idna
missing module named _sre.MAXREPEAT - imported by _sre, sre_constants
missing module named _warnings.warn_explicit - imported by _warnings, warnings
missing module named _warnings.filters - imported by _warnings, warnings
missing module named _warnings.once_registry - imported by _warnings, warnings
missing module named _warnings.default_action - imported by _warnings, warnings
missing module named _warnings.warn - imported by _warnings, warnings
missing module named strop.whitespace - imported by strop, string
missing module named strop.maketrans - imported by strop, string
missing module named strop.lowercase - imported by strop, string
missing module named strop.uppercase - imported by strop, string
missing module named itertools.islice - imported by itertools, repr, heapq
missing module named itertools.starmap - imported by itertools, collections
missing module named itertools.repeat - imported by itertools, collections
missing module named itertools.imap - imported by itertools, heapq, collections
missing module named itertools.tee - imported by itertools, heapq
missing module named itertools.izip - imported by itertools, heapq
missing module named itertools.count - imported by itertools, heapq, threading
missing module named itertools.chain - imported by itertools, tokenize, heapq, collections
missing module named org.PyStringMap - imported by org, copy
missing module named org - imported by copy
missing module named exceptions.ReferenceError - imported by exceptions, weakref
missing module named _weakref.ref - imported by _weakref, _weakrefset, weakref
missing module named _weakref.ReferenceType - imported by _weakref, weakref
missing module named _weakref.proxy - imported by _weakref, weakref
missing module named _weakref.getweakrefs - imported by _weakref, weakref
missing module named _weakref.getweakrefcount - imported by _weakref, weakref
missing module named _weakref.ProxyType - imported by _weakref, weakref
missing module named _weakref.CallableProxyType - imported by _weakref, weakref
missing module named copy.deepcopy - imported by copy, weakref
missing module named re._compile - imported by re, sre
missing module named re.__all__ - imported by re, sre
missing module named codecs.mbcs_encode - imported by codecs, encodings.mbcs
missing module named codecs.mbcs_decode - imported by codecs, encodings.mbcs
missing module named binascii.b2a_qp - imported by binascii, quopri
missing module named binascii.a2b_qp - imported by binascii, quopri
missing module named binascii.a2b_uu - imported by binascii, encodings.uu_codec
missing module named binascii.b2a_uu - imported by binascii, encodings.uu_codec
missing module named binascii.hexlify - imported by binascii, random
missing module named errno.EINVAL - imported by errno, StringIO
missing module named errno.ENOENT - imported by errno, gettext
missing module named cStringIO.StringIO - imported by cStringIO, gettext, pprint, shlex, tempfile, pickle, encodings.uu_codec, quopri, encodings.quopri_codec
missing module named struct.calcsize - imported by struct, ctypes
missing module named _struct.__doc__ - imported by _struct, struct
missing module named _struct._clearcache - imported by _struct, struct
missing module named _subprocess.STD_OUTPUT_HANDLE - imported by _subprocess, subprocess
missing module named _subprocess.CREATE_NEW_PROCESS_GROUP - imported by _subprocess, subprocess
missing module named _subprocess.STD_INPUT_HANDLE - imported by _subprocess, subprocess
missing module named _subprocess.STARTF_USESHOWWINDOW - imported by _subprocess, subprocess
missing module named _subprocess.CREATE_NEW_CONSOLE - imported by _subprocess, subprocess
missing module named _subprocess.STD_ERROR_HANDLE - imported by _subprocess, subprocess
missing module named _subprocess.STARTF_USESTDHANDLES - imported by _subprocess, subprocess
missing module named _subprocess.SW_HIDE - imported by _subprocess, subprocess
missing module named collections.namedtuple - imported by collections, inspect, unittest.util, difflib, doctest
missing module named cPickle.loads - imported by cPickle, collections
missing module named cPickle.dumps - imported by cPickle, collections
missing module named thread.get_ident - imported by thread, collections
missing module named thread._local - imported by thread, threading
missing module named thread.stack_size - imported by thread, threading
missing module named thread.allocate_lock - imported by thread, _strptime
missing module named collections.deque - imported by collections, shlex, threading
missing module named collections.OrderedDict - imported by collections, unittest.util
missing module named operator.itemgetter - imported by operator, collections, heapq
missing module named operator.eq - imported by operator, collections
missing module named operator.attrgetter - imported by operator, inspect
missing module named _collections.deque - imported by _collections, collections
missing module named _collections.defaultdict - imported by _collections, collections
missing module named time.time - imported by time, threading
missing module named time.sleep - imported by time, threading
missing module named datetime.date - imported by datetime, _strptime
missing module named _functools.partial - imported by _functools, functools
missing module named _functools.reduce - imported by _functools, functools
missing module named _hashlib.pbkdf2_hmac - imported by _hashlib, hashlib
missing module named math.sin - imported by math, random
missing module named math.sqrt - imported by math, random
missing module named math.cos - imported by math, random
missing module named math.acos - imported by math, random
missing module named math.ceil - imported by math, random
missing module named math.exp - imported by math, random
missing module named math.log - imported by math, random
missing module named math.e - imported by math, random
missing module named math.pi - imported by math, random
missing module named _io.DEFAULT_BUFFER_SIZE - imported by _io, io
missing module named _io.BytesIO - imported by _io, io
missing module named _io.open - imported by _io, io
missing module named _io.BufferedWriter - imported by _io, io
missing module named _io.FileIO - imported by _io, io
missing module named _io.BlockingIOError - imported by _io, io
missing module named _io.IncrementalNewlineDecoder - imported by _io, io
missing module named _io.BufferedReader - imported by _io, io
missing module named _io.BufferedRandom - imported by _io, io
missing module named _io.StringIO - imported by _io, io
missing module named _io.BufferedRWPair - imported by _io, io
missing module named _io.TextIOWrapper - imported by _io, io
missing module named _io.UnsupportedOperation - imported by _io, io
missing module named readline - imported by cmd, pdb
missing module named 'org.python'.PyStringMap - imported by 'org.python', pickle
missing module named 'org.python' - imported by pickle
missing module named fcntl - imported by tempfile, subprocess
missing module named threading.RLock - imported by threading, _threading_local
missing module named threading.current_thread - imported by threading, _threading_local
missing module named os.urandom - imported by os, random
missing module named riscosenviron._Environ - imported by riscosenviron, os
missing module named riscosenviron - imported by os
missing module named riscospath - imported by os
missing module named riscos._exit - imported by riscos, os
missing module named riscos - imported by os
missing module named ce._exit - imported by ce, os
missing module named ce - imported by os
missing module named _emx_link.link - imported by _emx_link, os
missing module named _emx_link - imported by os
missing module named os2._exit - imported by os2, os
missing module named os2 - imported by os
missing module named nt._isdir - imported by nt, ntpath
missing module named nt._getfullpathname - imported by nt, ntpath
missing module named nt._exit - imported by nt, os
missing module named pwd - imported by posixpath
missing module named posix._exit - imported by posix, os
missing module named posix - imported by os
missing module named resource - imported by posix
missing module named _ctypes._wstring_at_addr - imported by _ctypes, ctypes
missing module named _ctypes._string_at_addr - imported by _ctypes, ctypes
missing module named _ctypes._cast_addr - imported by _ctypes, ctypes
missing module named _ctypes._memset_addr - imported by _ctypes, ctypes
missing module named _ctypes._memmove_addr - imported by _ctypes, ctypes
missing module named _ctypes.get_last_error - imported by _ctypes, ctypes
missing module named _ctypes.set_last_error - imported by _ctypes, ctypes
missing module named _ctypes._check_HRESULT - imported by _ctypes, ctypes
missing module named _ctypes.set_conversion_mode - imported by _ctypes, ctypes
missing module named _ctypes._pointer_type_cache - imported by _ctypes, ctypes
missing module named _ctypes.POINTER - imported by _ctypes, ctypes
missing module named _ctypes._SimpleCData - imported by _ctypes, ctypes
missing module named _ctypes.get_errno - imported by _ctypes, ctypes
missing module named _ctypes.set_errno - imported by _ctypes, ctypes
missing module named _ctypes.alignment - imported by _ctypes, ctypes
missing module named _ctypes.addressof - imported by _ctypes, ctypes
missing module named _ctypes.resize - imported by _ctypes, ctypes
missing module named _ctypes.byref - imported by _ctypes, ctypes
missing module named _ctypes.sizeof - imported by _ctypes, ctypes
missing module named _ctypes.dlopen - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_STDCALL - imported by _ctypes, ctypes
missing module named _ctypes.LoadLibrary - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_USE_ERRNO - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_USE_LASTERROR - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_PYTHONAPI - imported by _ctypes, ctypes
missing module named _ctypes.FUNCFLAG_CDECL - imported by _ctypes, ctypes
missing module named _ctypes.FormatError - imported by _ctypes, ctypes
missing module named _ctypes.ArgumentError - imported by _ctypes, ctypes
missing module named _ctypes.RTLD_LOCAL - imported by _ctypes, ctypes
missing module named _ctypes.RTLD_GLOBAL - imported by _ctypes, ctypes
missing module named _ctypes.__version__ - imported by _ctypes, ctypes
missing module named _ctypes.CFuncPtr - imported by _ctypes, ctypes
missing module named _ctypes._Pointer - imported by _ctypes, ctypes
missing module named _ctypes.Structure - imported by _ctypes, ctypes
missing module named _ctypes.Array - imported by _ctypes, ctypes
missing module named _ctypes.Union - imported by _ctypes, ctypes

None of them refers Tix in any way - at least that I have found. I am also aware from my search that Tix is somewhat old, but it is what the program uses and I didn't want to change it since the author originally made it that way. He also managed to generate an .exe file for the program so not only that means it is possible to do it, but also that I'm probably doing something wrong here.

Thanks in advance.


Solution

  • Okay, I seem to have found the answer. After comparing the files in my python directory and the generated files, I found out that the problem is that py2exe, for some reason, is not copying the files from Tix.

    After that, I decided to Google again and found this page again, and noticed that I had a different Tix version from the one in the example, and just changed the script to match my version, making it work perfectly.

    Here is the script:

    import glob
    import os
    import sys
    from distutils.core import setup
    import py2exe
    
    def files(folder):
        for path in glob.glob(folder+'/*'):
            if os.path.isfile(path):
                yield path
    
    data_files=[
                ('.', glob.glob(sys.prefix+'/DLLs/tix84*.dll')),
                ('tcl/tix8.4.3', files(sys.prefix+'/tcl/tix8.4.3/')),
                ('tcl/tix8.4.3/bitmaps', files(sys.prefix+'/tcl/tix8.4.3/bitmaps/')),
                ('tcl/tix8.4.3/pref', files(sys.prefix+'/tcl/tix8.4.3/pref/')),
               ]
    
    setup(
          script_args=['py2exe'],
          windows=['pikasav.py'],
          data_files=data_files,
         )
    

    If you ever happen to come across this question in the future and have a different Tix version, just remember to change it if needed. Now I need to figure out a way to make this have the minimum number of files possible, but that's a whole different story.