-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve support for imports #11
Comments
|
One solution would be to search through the global objects, collect modules, assemble import code and then add it to the code passed to manim. The first two steps are easy: from types import ModuleType
@magics_class
class ManimMagics(Magics):
# ....
def extract_imports(self):
frame = find_ipython_frame(inspect.stack())
if not frame:
raise Exception('Could not find IPython frame')
globals_dict = frame[0].f_globals
modules = {
name: obj
for name, obj in globals_dict.items()
if (not name.startswith('_')) and isinstance(obj, ModuleType)
}
return '\n'.join(
assemble_import(module) for module in modules
) but writing the import statistics
from os import path
import os
sys = os.sys
import abc as xyz
assert assemble_import(statistics) = 'import statistics'
assert assemble_import(path) = 'from os import path'
assert assemble_import(sys) = 'from os import sys'
assert assemble_import(xyz) = 'import abc as xyz' All I had time for this weekend, maybe someone else will have more ideas/time to send pick up from there and send a PR - help wanted! |
Posted a question on the topic here: https://stackoverflow.com/questions/61049832/is-it-possible-to-generate-import-statement-from-the-module-file-in-python |
This code works:
!python3 -m manim example_scenes.py WarpSquare -pl
This code works also in jupyter:
But when
import numpy as np
was written in the cell before and already executed the code without this line can't find numpy:
Why doesn't the cell with magic
%%manim
find already imported libraries?The text was updated successfully, but these errors were encountered: