From 60c225a191dedbfd0328b6c43ae0a18d50eca780 Mon Sep 17 00:00:00 2001 From: Benjamin Hackl Date: Sun, 31 Jan 2021 18:24:21 +0100 Subject: [PATCH] Enhancement (of new feature): JupyterLab docker image and documentation for manim and IPython (#977) * fix import: move setting __version__ to top of __init__ * add simple Dockerfile for a manim-jupyterlab container * add section on jupyterlab in docker/readme.md * improve Dockerfile: separate user, install manim with all extras, upgrade to python 3.8 * remove separate jupyterlab docker image, adapt readme * add missing latex package * include link to interactive worksheet in documentation * Update README.md Co-authored-by: kolibril13 <44469195+kolibril13@users.noreply.github.com> --- README.md | 13 ++++++++++--- docker/Dockerfile | 26 +++++++++++++++++++++----- docker/readme.md | 9 +++++++++ docs/source/examples.rst | 4 ++++ manim/__init__.py | 15 ++++++++------- 5 files changed, 52 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3e6ad96e85..b98179475c 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,14 @@

PyPI Latest Release + Docker image + MIT License Reddit Twitter Discord Code style: black Documentation Status - Docker image Downloads CI
@@ -34,7 +35,12 @@ Manim is an animation engine for explanatory math videos. It's used to create pr ## Installation -Manim requires a few dependencies that must be installed prior to using it. Please visit the [Documentation](https://docs.manim.community/en/latest/installation.html) and follow the appropriate instructions for your operating system. +Manim requires a few dependencies that must be installed prior to using it. If you +want to try it out first before installing it locally, you can do so +[in our online Jupyter environment](https://mybinder.org/v2/gist/behackl/725d956ec80969226b7bf9b4aef40b78/HEAD?filepath=basic%20example%20scenes.ipynb). + +For the local installation, please visit the [Documentation](https://docs.manim.community/en/latest/installation.html) +and follow the appropriate instructions for your operating system. Once the dependencies have been installed, run the following in a terminal window: @@ -73,7 +79,8 @@ You should see your native video player program pop up and play a simple scene i [GitHub repository](master/example_scenes). You can also visit the [official gallery](https://docs.manim.community/en/latest/examples.html) for more advanced examples. Manim also ships with a `%%manim` IPython magic which allows to use it conveniently in JupyterLab (as well as classic Jupyter) notebooks. See the -[corresponding documentation](https://docs.manim.community/en/latest/reference/manim.utils.ipython_magic.ManimMagic.html) for some guidance. +[corresponding documentation](https://docs.manim.community/en/latest/reference/manim.utils.ipython_magic.ManimMagic.html) for some guidance and +[try it out online](https://mybinder.org/v2/gist/behackl/725d956ec80969226b7bf9b4aef40b78/HEAD?filepath=basic%20example%20scenes.ipynb). ## Command line arguments diff --git a/docker/Dockerfile b/docker/Dockerfile index 0d9d81c1fb..2c38a54174 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-slim +FROM python:3.8-slim RUN apt-get update -qq \ && apt-get install --no-install-recommends -y \ @@ -17,17 +17,33 @@ RUN wget -O /tmp/install-tl-unx.tar.gz http://mirror.ctan.org/systems/texlive/tl tar -xzf /tmp/install-tl-unx.tar.gz -C /tmp/install-tl --strip-components=1 && \ /tmp/install-tl/install-tl --profile=/tmp/texlive-profile.txt \ && tlmgr install \ - amsmath babel-english cm-super doublestroke dvisvgm fundus-calligra \ + amsmath babel-english cm-super doublestroke dvisvgm everysel fundus-calligra \ jknapltx latex-bin microtype ms physics preview ragged2e relsize rsfs \ setspace standalone tipa wasy wasysym xcolor xkeyval # clone and build manim COPY . /opt/manim WORKDIR /opt/manim -RUN pip install --no-cache . +RUN pip install --no-cache .[jupyterlab,webgl_renderer] +# required due to current incompatibility from latest jedi version +RUN pip install jedi==0.17.2 + +ARG NB_USER=manimuser +ARG NB_UID=1000 +ENV USER ${NB_USER} +ENV NB_UID ${NB_UID} +ENV HOME /manim + +RUN adduser --disabled-password \ + --gecos "Default user" \ + --uid ${NB_UID} \ + ${NB_USER} # create working directory for user to mount local directory into -WORKDIR /manim -RUN chmod 666 /manim +WORKDIR ${HOME} +USER root +RUN chown -R ${NB_USER}:${NB_USER} ${HOME} +RUN chmod 777 ${HOME} +USER ${NB_USER} CMD [ "/bin/bash" ] diff --git a/docker/readme.md b/docker/readme.md index 68f8d182f9..4931a630bb 100644 --- a/docker/readme.md +++ b/docker/readme.md @@ -35,6 +35,15 @@ Then, to render a scene `CircleToSquare` in a file `test_scenes.py`, call $ docker exec -it --user="$(id -u):$(id -g)" my-manim-container manim test.py CircleToSquare -qm ``` +## Jupyterlab +Another alternative is to use the docker image to spin up a local webserver running +JupyterLab in whose Python kernel manim is installed and can be accessed via the `%%manim` cell magic. +To use JupyterLab, run +``` +$ docker run -it -p 8888:8888 manimcommunity/manim jupyter lab --ip=0.0.0.0 +``` +and then follow the instructions in the terminal. + # Important notes When executing `manim` within a Docker container, several command line flags (in particular `-p` (preview file) and `-f` (show output file in the file browser)) are not supported. diff --git a/docs/source/examples.rst b/docs/source/examples.rst index aa43200bb6..762d670627 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -16,6 +16,10 @@ Enjoy this taste of Manim! the modules :mod:`~.tex_mobject`, :mod:`~.geometry`, :mod:`~.moving_camera_scene`, and many more. + Check out our `interactive Jupyter environment `_ + which allows running the examples online, without requiring a local + installation. + Also, visit our `Twitter `_ for more *manimations*! diff --git a/manim/__init__.py b/manim/__init__.py index 33e71e04d3..51c0934159 100644 --- a/manim/__init__.py +++ b/manim/__init__.py @@ -1,5 +1,13 @@ #!/usr/bin/env python +try: + import importlib.metadata as importlib_metadata +except ModuleNotFoundError: + import importlib_metadata + +__version__ = importlib_metadata.version(__name__) + + # Importing the config module should be the first thing we do, since other # modules depend on the global config dict for initialization. from ._config import * @@ -96,10 +104,3 @@ ipy.register_magics(ManimMagic) from .plugins import * - -try: - import importlib.metadata as importlib_metadata -except ModuleNotFoundError: - import importlib_metadata - -__version__ = importlib_metadata.version(__name__)