ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
19.95k stars 1.48k forks source link

Manim mishandling imports or import confusion #2097

Closed dalanmiller closed 2 years ago

dalanmiller commented 2 years ago

Description of bug / unexpected behavior

My file structure is as follows:

# root of git repo
.git
└── project
    ├── __init__.py
    ├── utils
    │   ├── __init__.py
    │   ├── timeline.py
    │   └── utils.py
    ├── scenarios
    │   ├── __init__.py
    │   └── basic.py

I have a Scene defined in basic.py. basic.py also has an import from timeline.py. Whether I use an absolute or relative import I get an error when running manim render:

Using: from project.utils.utils import function I get: ModuleNotFoundError: No module named 'project'

Using: from ..utils.utils import function I get: ImportError: attempted relative import with no known parent package

The behavior is the same no matter what directory I run manim render from, e.g. in either the root folder or in the /project/scenarios folder.

I'm running manim render -pql project/scenarios/basic.py AnimateScenario

What am I doing wrong here from an import perspective / why is manim causing this behavior?

Expected behavior

Expect manim render ... to run successfully with current reasonable usage of imports in my project

How to reproduce the issue

Replicate folder structure above.

Logs

Terminal output ``` PASTE HERE OR PROVIDE LINK TO https://pastebin.com/ OR SIMILAR ```

System specifications

System Details - OS (with version, e.g Windows 10 v2004 or macOS 10.15 (Catalina)): Mac OS X - RAM: 16GB - Python version (`python/py/python3 --version`): `3.9.7` - Installed modules (provide output from `pip list`): ``` ❯ poetry show  ✔  1889  22:48:50 attrs 21.2.0 Classes Without Boilerplate backports.entry-points-selectable 1.1.0 Compatibility shim providing selectable entry points for older implementations certifi 2021.5.30 Python package for providing Mozilla's CA Bundle. charset-normalizer 2.0.5 The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet. click 8.0.1 Composable command line interface toolkit click-default-group 1.2.2 Extends click.Group to invoke a command without explicit subcommand name cloup 0.7.1 Option groups and subcommand help sections for pallets/click colorama 0.4.4 Cross-platform colored terminal text. colour 0.1.5 converts and manipulates various color representation (HSL, RVB, web, X11, ...) commonmark 0.9.1 Python parser for the CommonMark Markdown spec cython 0.29.24 The Cython compiler for writing C extensions for the Python language. decorator 5.1.0 Decorators for Humans distlib 0.3.2 Distribution utilities filelock 3.0.12 A platform independent file lock. glcontext 2.3.4 Portable OpenGL Context idna 3.2 Internationalized Domain Names in Applications (IDNA) iniconfig 1.1.1 iniconfig: brain-dead simple config-ini parsing manim 0.10.0 Animation engine for explanatory math videos. manimpango 0.3.0 Bindings for Pango for using with Manim. mapbox-earcut 0.12.10 Python bindings for the mapbox earcut C++ polygon triangulation library. moderngl 5.6.4 ModernGL: High performance rendering for Python 3 moderngl-window 2.4.0 A cross platform helper library for ModernGL making window creation and resource loading simple multipledispatch 0.6.0 Multiple dispatch networkx 2.6.3 Python package for creating and manipulating graphs and networks numpy 1.21.1 NumPy is the fundamental package for array computing with Python. packaging 21.0 Core utilities for Python packages pillow 8.3.2 Python Imaging Library (Fork) platformdirs 2.3.0 A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir". pluggy 1.0.0 plugin and hook calling mechanisms for python py 1.10.0 library with cross-python path, ini-parsing, io, code, log facilities pycairo 1.20.1 Python interface for cairo pydub 0.25.1 Manipulate audio with an simple and easy high level interface pyglet 1.5.21 Cross-platform windowing and multimedia library pygments 2.10.0 Pygments is a syntax highlighting package written in Python. pyobjc-core 7.3 Python<->ObjC Interoperability Module pyobjc-framework-cocoa 7.3 Wrappers for the Cocoa frameworks on macOS pyparsing 2.4.7 Python parsing module pyrr 0.10.3 3D mathematical functions using NumPy pytest 6.2.5 pytest: simple powerful testing with Python python-dateutil 2.8.2 Extensions to the standard Python datetime module requests 2.26.0 Python HTTP for Humans. rich 10.11.0 Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal scipy 1.6.1 SciPy: Scientific Library for Python screeninfo 0.6.7 Fetch location and size of physical screens. six 1.16.0 Python 2 and 3 compatibility utilities stripe 2.60.0 Python bindings for the Stripe API toml 0.10.2 Python Library for Tom's Obvious, Minimal Language tox 3.24.4 tox is a generic virtualenv management and test command line tool tqdm 4.62.3 Fast, Extensible Progress Meter urllib3 1.26.6 HTTP library with thread-safe connection pooling, file post, and more. virtualenv 20.8.0 Virtual Python Environment builder watchdog 2.1.5 Filesystem events monitoring ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): + Installed LaTeX packages:
FFMPEG Output of `ffmpeg -version`: ``` ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers built with Apple clang version 12.0.5 (clang-1205.0.22.9) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4_2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-avresample --enable-videotoolbox libavutil 56. 70.100 / 56. 70.100 libavcodec 58.134.100 / 58.134.100 libavformat 58. 76.100 / 58. 76.100 libavdevice 58. 13.100 / 58. 13.100 libavfilter 7.110.100 / 7.110.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 9.100 / 5. 9.100 libswresample 3. 9.100 / 3. 9.100 libpostproc 55. 9.100 / 55. 9.100 ```

Additional comments

dalanmiller commented 2 years ago

Forgot to try the following which works successfully:

$ poetry shell
python3 -m manim render -pql project/scenarios/basic.py AnimateScenario