Failed to execute script 'main' due to unhandled exception: maximum recursion depth exceeded

2,084 views
Skip to first unread message

Glen Rubin

unread,
Feb 16, 2023, 8:53:38 AM2/16/23
to Kivy users support
If I 'compile' a windows exectuable using PyInstaller and turn console off in the spec file options than the program fails to run yielding: Failed to execute script 'main' due to unhandled exception: maximum recursion depth exceeded

The traceback is very very long, but I will paste some highlights that hint what may be going on.  It looks like maybe kivy is trying to log something and without console is raising the error.  I tried explicitly turning off logging in kivy with the following, which didn't work:  Config.set('kivy', 'log_enable', 0)

Traceback (most recent call last):
  File "logging\__init__.py", line 1103, in emit
AttributeError: 'NoneType' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "logging\__init__.py", line 1103, in emit
AttributeError: 'NoneType' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "logging\__init__.py", line 1103, in emit
AttributeError: 'NoneType' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "logging\__init__.py", line 1103, in emit
AttributeError: 'NoneType' object has no attribute 'write'

This repeats a few thousand times and then prints:

Traceback (most recent call last):
  File "logging\__init__.py", line 1103, in emit
AttributeError: 'NoneType' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "kivy\logger.py", line 248, in emit
  File "kivy\logger.py", line 222, in _configure
  File "logging\__init__.py", line 1477, in info
  File "logging\__init__.py", line 1624, in _log
  File "logging\__init__.py", line 1634, in handle
  File "logging\__init__.py", line 1696, in callHandlers
  File "logging\__init__.py", line 968, in handle
  File "logging\__init__.py", line 1108, in emit
  File "logging\__init__.py", line 1021, in handleError
  File "kivy\logger.py", line 338, in write
  File "logging\__init__.py", line 1489, in warning
  File "logging\__init__.py", line 1624, in _log
  File "logging\__init__.py", line 1634, in handle
  File "logging\__init__.py", line 1696, in callHandlers
  File "logging\__init__.py", line 968, in handle
  File "logging\__init__.py", line 1108, in emit
  File "logging\__init__.py", line 1021, in handleError
  File "kivy\logger.py", line 338, in write
  File "logging\__init__.py", line 1489, in warning
  File "logging\__init__.py", line 1624, in _log
  File "logging\__init__.py", line 1634, in handle
  File "logging\__init__.py", line 1696, in callHandlers
  File "logging\__init__.py", line 968, in handle
  File "logging\__init__.py", line 1108, in emit
  File "logging\__init__.py", line 1021, in handleError
  File "kivy\logger.py", line 338, in write
  File "logging\__init__.py", line 1489, in warning
  File "logging\__init__.py", line 1624, in _log
  File "logging\__init__.py", line 1634, in handle
  File "logging\__init__.py", line 1696, in callHandlers
  File "logging\__init__.py", line 968, in handle
  File "logging\__init__.py", line 1108, in emit
  File "logging\__init__.py", line 1021, in handleError
  File "kivy\logger.py", line 338, in write
  File "logging\__init__.py", line 1489, in warning

Glen Rubin

unread,
Feb 16, 2023, 9:06:22 AM2/16/23
to kivy-...@googlegroups.com
I just tried turning off kivy console messages as well using the following, which makes no difference:

import os
os.environ["KIVY_NO_CONSOLELOG"] = "1"



--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/_Lyy5WBk6Kc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/4d3ea7f4-a566-42ad-aab3-f1eee90c3804n%40googlegroups.com.

Elliot Garbus

unread,
Feb 16, 2023, 9:08:06 AM2/16/23
to kivy-...@googlegroups.com

That is a strange issue. 

 

Here is the spec file I use for Windows.  It is similar – but different than the macos specfile.

 

# -*- mode: python -*-

from kivy_deps import sdl2, glew

block_cipher = None
app_name = 'Your App Name'
win_icon = '../Images/Your icon.ico'

a = Analysis(['../main.py'],
             pathex=[],
             binaries=[],
             datas=[('../*.kv', '.'),
                    ('../Images/*.png', './Images')],  # change as needed
             hiddenimports=['win32timezone'], # required if filebrowser is used
             hookspath=[],
             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,
          [],
          exclude_binaries=True,
          name=app_name,
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          console=False,
          icon=win_icon)
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=False,
               name=app_name)

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Elliot Garbus

unread,
Feb 16, 2023, 9:08:35 AM2/16/23
to kivy-...@googlegroups.com

What is in your log file?

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CABw5z-DZwNPo4SQX8cZDQx_JbwOhL21saHtjyhgO_H7pxrpEZw%40mail.gmail.com.

 

Glen Rubin

unread,
Feb 16, 2023, 9:45:45 AM2/16/23
to kivy-...@googlegroups.com
i don't have a log file lol... i think i should post this to the pyinstaller group

Elliot Garbus

unread,
Feb 16, 2023, 9:57:07 AM2/16/23
to kivy-...@googlegroups.com

Kivy creates a log file.  On Windows it is located at:

C:\Users\your_user_name\.kivy\logs

Glen Rubin

unread,
Feb 16, 2023, 9:57:10 AM2/16/23
to kivy-...@googlegroups.com
well i just tried posting to pyinstaller, but my message doesn't show up...maybe b/c im new there and they have a filter on new users...idk

Glen Rubin

unread,
Feb 16, 2023, 10:18:58 AM2/16/23
to kivy-...@googlegroups.com
thankyou for that info eliot!!  Logs report some missing modules...i'll try to install and see if errors resolve.

Elliot Garbus

unread,
Feb 16, 2023, 10:36:00 AM2/16/23
to kivy-...@googlegroups.com

The missing modules can sometimes because pyinstaller does not see them in your source code.

You can add them to the hiddenimports list in the spec file or explicitly import them in python.

Glen Rubin

unread,
Feb 16, 2023, 4:09:33 PM2/16/23
to kivy-...@googlegroups.com
the advice i got on the pyinstaller google group as follows:

I have come across similar before. You probably have logger set to write to stdout &/or stderr, however, in the compiled application stdout, stderr = None, None hence the errors. The trick that I used was to check if they are currently None and if so either don’t initialise the logger or make sure that all logging is sent to a file.

I have tried turning off all logging as well as logging to a file, yet still get the same errors.

Elliot Garbus

unread,
Feb 16, 2023, 5:03:33 PM2/16/23
to kivy-...@googlegroups.com
Are you doing something unusual with logging?
What level do you have logging set to?

Sent from my iPhone

On Feb 16, 2023, at 2:09 PM, Glen Rubin <rubi...@gmail.com> wrote:



Glen Rubin

unread,
Feb 16, 2023, 5:14:07 PM2/16/23
to kivy-...@googlegroups.com
No I never even set the logging options and now I have turned logging off to no avail. 

Glen Rubin

unread,
Feb 16, 2023, 5:56:03 PM2/16/23
to kivy-...@googlegroups.com
If I turn kivy logging on, this is what i see... nothing wayward i promise!

[INFO   ] Logger: Record log in C:\Users\rubin\.kivy\logs\kivy_23-02-16_1.txt
[INFO   ] Kivy: v2.1.0
[INFO   ] Kivy: Installed at "C:\Users\rubin\Desktop\SpectrumCGM\SpectrumApp\dist\spectrumCGM\kivy\__init__.pyc"
[INFO   ] Python: v3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)]
[INFO   ] Python: Interpreter at "C:\Users\rubin\Desktop\SpectrumCGM\SpectrumApp\dist\spectrumCGM\spectrumCGM.exe"
[INFO   ] Logger: Purge log fired. Processing...
[INFO   ] Logger: Purge finished!
[INFO   ] Factory: 189 symbols loaded
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] Text: Provider: sdl2
[INFO   ] Window: Provider: sdl2
[INFO   ] GL: Using the "OpenGL" graphics system
[INFO   ] GL: GLEW initialization succeeded
[INFO   ] GL: Backend used <glew>
[INFO   ] GL: OpenGL version <b'4.6.0 NVIDIA 391.35'>
[INFO   ] GL: OpenGL vendor <b'NVIDIA Corporation'>
[INFO   ] GL: OpenGL renderer <b'GeForce GT 730/PCIe/SSE2'>
[INFO   ] GL: OpenGL parsed version: 4, 6
[INFO   ] GL: Shading version <b'4.60 NVIDIA'>
[INFO   ] GL: Texture max size <16384>
[INFO   ] GL: Texture max units <32>
[INFO   ] Window: auto add sdl2 input provider
[INFO   ] Window: virtual keyboard not allowed, single mode, not docked
[INFO   ] Base: Start application main loop
[INFO   ] GL: NPOT texture support is available
[INFO   ] Base: Leaving application in progress...

Glen Rubin

unread,
Feb 17, 2023, 11:56:38 AM2/17/23
to kivy-...@googlegroups.com
Found the problem!  In config.ini debug was set to True.  

Glen Rubin

unread,
Feb 17, 2023, 11:56:56 AM2/17/23
to kivy-...@googlegroups.com
I changed it to critical and now works fine

Francisco Ponce

unread,
Sep 11, 2023, 1:00:01 AM9/11/23
to kivy-...@googlegroups.com
Hi Glen and Everyone

Having the same issue here

Tried with different versions of pyinstaller, also sending logging to a txt, but still doesnt work

It happens when I turn the console off, exactly the same error as you

Can you please explain "Found the problem!  In config.ini debug was set to True.",  "I changed it to critical and now works fine"

Where is the config.ini file?

Thanks in advance



--
Francisco Ponce

elli...@cox.net

unread,
Sep 11, 2023, 1:42:30 PM9/11/23
to kivy-...@googlegroups.com

The issue is that the behavior changed in V5.7 of pyinstaller.  Pyinstaller now sets stderr to None with the console is set to False.  This is the same behavior as pythonw. 

 

Here are some workarounds:

  1. Turn off the console log: 
    1. At the top of the file before kivy.app is imported
                     i.   import os
                    ii.   os.environ["KIVY_NO_CONSOLELOG"] = "1"
2)     Use an older version of pyinstaller.
a.      pip install pyinstaller==5.6.2 pyinstaller-hooks-contrib==2022.13
 
The ini file is located at: C:\Users\YourUserName\.kivy

Francisco Ponce

unread,
Sep 11, 2023, 2:08:58 PM9/11/23
to kivy-...@googlegroups.com
Thank you so much Elliot

It was so easy, os.environ["KIVY_NO_CONSOLELOG"] = "1" worked

Using an older version of pyinstaller gave me another error





--
Francisco Ponce
Reply all
Reply to author
Forward
0 new messages