Refactor the structure of the package and add configuration guidelines#1366
Refactor the structure of the package and add configuration guidelines#13663b1b merged 16 commits into3b1b:masterfrom TonyCrane:package-improve
Conversation
|
Most of this is certainly in the right direction, thank you.
Given that the current use of manimlib/imports.py is not the best practice, I'd be hesitant to make it something that's called by default when you import the package. At the very least, it would be best to separate out the non-manim libraries that it imports at the bottom. In fact, arguably most of those should be removed, and we should encourage more explicit imports of numpy, math, etc. If for someone's personal use-case they want to bring all those in with a single highly-implicit import call, they can always do that, but I don't think it should be systematized into the structure of manim.
I don't think the first time someone runs manim they should have to fill all this out. It's a nicer user experience if it falls back on some defaults so they can at least jump in and start running scenes. It might be better to print a warning that certain defaults are used, which points the user to where they can go to set their own defaults for where files are output, etc. |
|
After asking the manim community a little about their decisions, I suppose it seems fine to put all the "from import *" commands in the __init__.py file, but we should remove the non-manim imports from there. |
I have deleted the non-manim imports in
I re-added the global default configuration But there is another issue here. In Windows, if |
|
When I run it right now with the manimgl command, there seems to be an issue in initializing the Window. I can try to look into it, but do you have any sense of what might have affected Window? It works fine for file writing. |
|
But there is no problem running manimgl on my computer. And I probably didn’t make any changes related to Window. envsOS: Windows 10Python: Python 3.7.9 (anaconda env) pyglet: 1.5.14 Maybe it's a problem with Python 3.9 ? I am trying. |
|
I used anaconda to create a clean Python 3.9 environment, and executed with the following commands, successfully running without error. conda create -n py39 python=3.9
conda activate py39
pip install cmake -i https://pypi.tuna.tsinghua.edu.cn/simple/ # for mapbox_earcut
pip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple/
manimglpip freeze |
|
Creating a similar clean environment with all the same commands, I still run into some OpenGL related issue. (I'm on OSX 11.1) Similar pip freeze |
|
I merged your commits after this pr and created a new environment, and no errors appeared. This shows that there is no problem on Windows. I asked a friend of mine who also uses MacOS, and he has similar problems when using the new version of manim. He sent me the following document on how to fix it, I hope it can help you. In the latest macOS Big Sur, the default location of OpenGL has been changed from the library to the frameworks under the library, so in the current version PyOpenGL cannot find the original location, which will cause an error For this, the long-term solution is to wait for the next Python update.
|
|
Ah, my apologies, I should have been able to recognize that. It's an issue that shows up in other places too but is fixed in Python 3.9, which is why that's what I've usually been using. In setting up the clean environment above, I guess I had forgotten this fact. Still, when I set it up in a python 3.9 environment, I get that same separate issue, which seems to be related to the Window not having a proper OpenGL context. I'm still very confused by why anything from this PR (which seems unrelated to the OpenGL context) would have changed this. Mostly I remain confused by what the issue is, exactly. |
|
I suspect it has something to do with how the PygletWindow is being used, and that I probably didn't know what I was doing as I wrote that. Let me look into that a bit more. |
|
I think this may be a bug on Big Sur. |
|
Or maybe you can try to create a new Python 3.8 environment and run it? |
|
Hey Grant. I am the “friend” up there, and I’m currently using the macOS on my MacBook, so I also had to face this problem, though I found a way to solve it. And here’s what I did: |
|
I think there are two separate issues. One has to do with Big Sur and find_library, which it seems can be fixed either the way you're describing, by changing the OpenGL code, or by updating to a sufficiently new version of Python, where 3.9 seems to work for me. But it looks like something separate is going on too, associated with the moderngl window. I suspect it has to do with something wrong I did when it comes to initializing that window and the OpenGL context. In the same environment where master branch runs fine on my system, something about the changes on this branch cause this window initializing issue to happen. This happens in environments with both 3.8 and 3.9, and looks unrelated to the question of loading libraries. I don't think it's anything wrong with what @TonyCrane wrote, but I'm still hesitant to merge while knowing it will break on some systems, at least without knowing why. |
|
Okay, this is incredibly bizarre. I could fix the issue by removing the line From __init__.py. Something about the import line being called before the window creation seemed to affect things. |
Ohh! If that's the problem then move the import statement in |
|
It's also solved by calling "from manimlib.window import *" above that line. This seems like it's exposing a deeper problem, though, which I'll look into. |
|
But this will cause |
|
Am also struggling with the OpenGL problem. No apparent resolution in sight. Running Mac OS Big Sur 11.2.3 and I see that: I gather that not only is OpenGL a deprecated library, but also the Python-native routines to find libraries are also undergoing revisions in an effort to do better at finding binaries to prevent these kinds of problems. So... I've been >>stuck in a ditch<< for days trying to do what should be a simple install. Sigh.... Help I think I could use: (B) What command can I run that will guarantee the download, installation, and report-of-location of the OpenGL library? It'd be great if there was some easy way to easily install a fresh OpenGL lib based on Apple's new "Metal" API; but I have failed to find an easy way to do this. Your help would be appreciated! :) BTW -- me and my son just LOVE the vids and graphics from the 3b1b team! Stay strong you fine people! |
|
I had this problem on Python 3.8 but changing to 3.9 solved the issue. Worth a try for anyone who is on 3.8 and get |
Motivation
The current
manimlibis relatively inconsistent with the package specification, so some slight refactoring has been carried out.And added an automation guide for setting
custom_default.ymlProposed changes
manimlib/__init__.pyintomanimlib/__main__.pyas an entry point of manim and remove all non-manim imports.manimlib/imports.pyintomanimlib/__init__.py. So we can usefrom manimlib import *to import this package.__init__.pyfor each foldermanim.py, Usemanimgl(ormanim-render) instead ofpython manim.py.custom_defaults.yml -> custom_config.yml,defaults.yml -> default_config.ymlcustom_config.ymlormanimlib/default_config.yml)custom_config.ymland using thedefault_config.yml--config. Usemanimgl --configto create a config file according to the guide for a second time.