Manim cannot import external modules
- Linguagem predominante
- Python
- Estrelas
- 93.9k
- Forks
- 7.7k
- Merge médio
- 2d 13h
- PRs com merge (30d)
- 4
Descrição
I'm trying to import a module called eulers_method in my manim script called anim_engine, however, manim cannot find the eulers_method module
```
(env) ⬢[slaavn@toolbox manim]$ manim anim_engine.py Simulation -pl
Traceback (most recent call last):
File "/var/home/slaavn/Programs/manim/env/bin/manim", line 10, in
sys.exit(main())
File "/var/home/slaavn/Programs/manim/env/lib64/python3.8/site-packages/manimlib/__init__.py", line 9, in main
config = manimlib.config.get_configuration(args)
File "/var/home/slaavn/Programs/manim/env/lib64/python3.8/site-packages/manimlib/config.py", line 155, in get_configuration
module = get_module(args.file)
File "/var/home/slaavn/Programs/manim/env/lib64/python3.8/site-packages/manimlib/config.py", line 150, in get_module
spec.loader.exec_module(module)
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "anim_engine.py", line 12, in
from eulers_method.py import *
ModuleNotFoundError: No module named 'eulers_method'
```
if I run ls in my current dir, you can see both files are in the same directory
```
(env) ⬢[slaavn@toolbox manim]$ ls
:w __pycache__ anim_engine.py double_pend.py eulers_method.py media time.npy
'\' angles.npy anim_pend.py env manim_phys.py position.npy trial.py
```
And if I run os.getcwd() from the file it matches the directory I called manim from
Output of os.getcwd()
`/var/home/slaavn/Programs/manim`
Output of pwd
```
(env) ⬢[slaavn@toolbox manim]$ pwd
/var/home/slaavn/Programs/manim
```
I also tried to run os.getcwd() from config.py and get the same output
I thought the problem might have been my manim installation, because it was a system installation. I uninstalled manim and reinstalled it using `--no-cache-dir` flag for pip, but I got the same error. I then tried to install it in a virtual environment, and as you can see from above, I encountered the same error.
As for other things I have tried that have failed:
- Changing the import of eulers_method to be before the manimlib imports
- Importing from eulers_method.py instead of eulers_method
- Downgrading from python3.8 to python3.7
I have no clue as to what's going on at this point
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Veja manimlib/config.py, especificamente a função get_module por volta da linha 150. O problema é sobre o carregamento de módulos do Python quando o manim executa um script. Comece entendendo como o diretório atual é adicionado ao sys.path. Verifique se o import funciona quando executa o script diretamente com Python em comparação com a execução via manim CLI. A correção provavelmente envolve ajustar o carregamento do módulo para incluir o diretório do script.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Domínio
- cli, tooling
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 65/100