You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LaTeX chemfig库安装失败求助:Google Colab中安装Manim、Chanim及通过\tlmgr安装chemfig遇阻

Hey there! I’ve dealt with similar headaches setting up Manim, Chanim, and the chemfig LaTeX package on Google Colab before—let’s walk through a reliable, step-by-step fix to get everything working smoothly for you.

Step 1: Clear Out Broken Leftover Installs

First, let’s clean up any half-installed packages or conflicting files from your previous attempts. Run these commands to wipe old TeX Live and Python package residues:

!pip uninstall -y manim chanim
!sudo apt-get remove --purge texlive*
!sudo apt-get autoremove --purge
!sudo rm -rf /usr/local/texlive /var/lib/texmf
Step 2: Install TeX Live + chemfig Properly

Colab’s default TeX setup is often missing niche packages like chemfig. Let’s install a minimal but complete base TeX distribution, then use tlmgr to add chemfig explicitly:

# Update apt repositories first
!sudo apt-get update
# Install core TeX packages
!sudo apt-get install -y texlive-base texlive-latex-extra texlive-fonts-recommended
# Install chemfig via tlmgr (TeX Live’s package manager)
!tlmgr install chemfig

If you get a tlmgr: command not found error, install the full TeX Live distribution instead (it’s larger but avoids missing dependencies):

!sudo apt-get install -y texlive-full
Step 3: Install Manim and Chanim Without Conflicts

Manim Community Edition is the most stable version for Colab, and Chanim relies on it. Install them in order to avoid dependency clashes:

# Install Manim Community Edition
!pip install manim
# Install Chanim (use the latest compatible version)
!pip install chanim

If you hit dependency errors, try forcing a reinstall with updated pip:

!pip install --upgrade pip
!pip install --force-reinstall manim chanim
Step 4: Verify Everything Works

Let’s confirm each component is installed correctly:

  • Check Manim version:
    !manim --version
    
  • Check Chanim import:
    import chanim
    print(f"Chanim version: {chanim.__version__}")
    
  • Test chemfig compilation:
    # Create a test LaTeX file with a chemical structure
    !echo '\documentclass{article}
    \usepackage{chemfig}
    \begin{document}
    \chemfig{CH3-CH2-OH}
    \end{document}' > test_chemfig.tex
    # Compile it with pdflatex
    !pdflatex test_chemfig.tex
    

If you see Output written on test_chemfig.pdf, chemfig is working.

Quick Troubleshooting Tips
  • If Manim throws LaTeX errors: Make sure it’s using the correct TeX compiler path. Add this to your Manim code:
    from manim import *
    config.tex_compiler = "pdflatex"
    config.tex_path = "/usr/bin/pdflatex"
    
  • If Chanim fails to import: Double-check that you installed Manim first—Chanim is a Manim extension and requires it as a dependency.

内容的提问来源于stack exchange,提问作者GameDev Rony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 03:42:39