Skip to content

[Bug] _is_manim_available() fails in a venv without PATH (systemd services) #222

Description

@ogarcia

Description

CaptchaGenerator._is_manim_available() (generator.py:223) checks for the manim executable via shutil.which("manim"):

def _is_manim_available(self) -> bool:
    manim_bin = shutil.which("manim")
    if not manim_bin:
        return False
    return True

This makes CaptchaAutoGenerator.start() return False whenever the venv's bin/ directory is not on PATH, which is the normal case for a systemd service invoking /path/to/.venv/bin/python directly: systemd's default PATH is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin and does not include the venv. Manim is installed and fully importable, but the generator refuses to start.

Why the check looks unnecessary

The library never invokes the manim entry point. The only execution path is generator.py:192, which runs the current interpreter with the launcher script:

cmd = [sys.executable, str(self.MANIM_LAUNCHER), json_manim_data]

Also, generator.py:41 already does import manim at module level, so an actually-missing manim would raise ImportError at import time, long before this check ever runs. The executable is being used as a proxy for "is manim installed?", but it answers a different question than the one that matters.

Suggested fix

Check module importability instead of the executable, since that is what the subprocess actually needs:

def _is_manim_available(self) -> bool:
    return importlib.util.find_spec("manim") is not None

(importlib.util is already used this way in manim_launcher.py.)

Secondary issue: silent failure

start() returns False with no log entry explaining why — unavailable versus already running are indistinguishable from the consumer's side. A logger.error("Manim module not found") on the unavailable path would make this diagnosable from logs instead of requiring a read through the library source.

Environment

  • manim-captcha 1.2.2
  • manim 0.19.2
  • Python 3.14
  • Arch Linux, running under systemd

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions