Search code examples
python-3.xmanim

Manim Community: `interactive_embed()` causes IPython Curruption (sqlite3.ProgrammingError)


Project Structure

swac_animation

      |--- maths.py

maths.py

from manim import *
from manim.opengl import *

config.renderer = "opengl"

class WhatIsFunction(Scene):
    def construct(self):
        hello_world = Tex("Hello World!").scale(3)
        self.play(Write(hello_world))
        self.interactive_embed()

Error Description

Produces this error log when the program hits self.interactive_embed()

(venv) PS D:\JetBrains\PycharmProjects\swac_animation> manim -qm -p --renderer=opengl maths.py WhatIsFunction
Manim Community v0.17.3

Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0 -- An enhanced Interactive Python. Type '?' for help.

Loading history failed
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 37684 and this is thread id 52360.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\core\history.py", line 77, in catch_corrupt_db
    return f(self, *a, **kw)
           ^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\core\history.py", line 660, in get_tail
    self.writeout_cache()
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\core\history.py", line 60, in only_when_enabled
    return f(self, *a, **kw)
           ^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\core\history.py", line 834, in writeout_cache
    self._writeout_input_cache(conn)
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\core\history.py", line 815, in _writeout_input_cache
    with conn:
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 37684 and this is thread id 52360.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\buffer.py", line 422, in load_history_done
    f.result()
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\buffer.py", line 410, in load_history
    async for item in self.history.load():
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\history.py", line 59, in load
    self._loaded_strings = list(self.load_history_strings())
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\terminal\interactiveshell.py", line 175, in load_history_strings
    for __, ___, cell in self.shell.history_manager.get_tail(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\core\history.py", line 104, in catch_corrupt_db
    self.hist_file.rename(newpath)
  File "C:\Users\fedel\AppData\Local\Programs\Python\Python311\Lib\pathlib.py", line 1175, in rename
    os.rename(self, target)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\fedel\\.ipython\\profile_default\\history.sqlite' -> 'C:\\Users\\fedel\\.ipython\\profile_default\\history-corrupt-2023-06-20T20.29.05.994329.sqlite
'

Unhandled exception in event loop:
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\buffer.py", line 410, in load_history
    async for item in self.history.load():
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\history.py", line 59, in load
    self._loaded_strings = list(self.load_history_strings())
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\terminal\interactiveshell.py", line 175, in load_history_strings
    for __, ___, cell in self.shell.history_manager.get_tail(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\core\history.py", line 104, in catch_corrupt_db
    self.hist_file.rename(newpath)
  File "C:\Users\fedel\AppData\Local\Programs\Python\Python311\Lib\pathlib.py", line 1175, in rename
    os.rename(self, target)

Exception [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\fedel\\.ipython\\profile_default\\history.sqlite' -> 'C:\\Users\\fedel\\.ipython\\profile_default\\history-corrupt-2023-06-20T20.29.05.994329.sqlite'      
Press ENTER to continue...

Pressing ENTER enters the normal IPython interactive console, but error is raised whenever parenthesis is entered OR trying to run the line by pressing enter:

In [1]: 1

Unhandled exception in event loop:
  File "C:\Users\fedel\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\input\win32.py", line 613, in ready
    callback()
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\application\application.py", line 698, in read_from_input
    self.key_processor.process_keys()
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 272, in process_keys
    self._process_coroutine.send(key_press)
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 187, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 322, in _call_handler
    handler.call(event)
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_bindings.py", line 126, in call
    result = self.handler(event)
             ^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\terminal\shortcuts\__init__.py", line 405, in handle_return_or_newline_or_execute
    return newline_or_execute_outer(shell)(event)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\terminal\shortcuts\__init__.py", line 428, in newline_or_execute
    status, indent = shell.check_complete(check_text)
                     ^^^^^^^^^^^^^^^^^^^^

Exception 'NoneType' object has no attribute 'check_complete'
Press ENTER to continue...

In [1]: play(

Unhandled exception in event loop:
  File "C:\Users\fedel\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\input\win32.py", line 613, in ready
    callback()
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\application\application.py", line 698, in read_from_input
    self.key_processor.process_keys()
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 272, in process_keys
    self._process_coroutine.send(key_press)
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 170, in _process
    matches = self._get_matches(buffer)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 128, in _get_matches
    return [b for b in self._bindings.get_bindings_for_keys(keys) if b.filter()]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\key_binding\key_processor.py", line 128, in <listcomp>
    return [b for b in self._bindings.get_bindings_for_keys(keys) if b.filter()]
                                                                     ^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\filters\base.py", line 134, in __call__
    return all(f() for f in self.filters)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\filters\base.py", line 134, in <genexpr>
    return all(f() for f in self.filters)
               ^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\prompt_toolkit\filters\base.py", line 248, in __call__
    return self.func()
           ^^^^^^^^^^^
  File "D:\JetBrains\PycharmProjects\swac_animation\venv\Lib\site-packages\IPython\terminal\shortcuts\filters.py", line 84, in auto_match
    return shell.auto_match
           ^^^^^^^^^^^^^^^^

Exception 'NoneType' object has no attribute 'auto_match'
Press ENTER to continue...

System Specifications

Python: 3.11

Manim: v0.17.3

OS: Windows 10


Solution

  • There is no problem with your manim version and your python version. The problem is with IPython version. You need to install this version of IPython:

    pip install IPython==8.0.1
    

    I downgraded IPython to 8.0.1 and the code worked pretty well. Below picture shows the result on my machine: enter image description here