ETE 3 (Environment for Tree Exploration)
ETE (Environment for Tree Exploration) 3 is a Python toolkit for the manipulation, analysis, and visualization of phylogenetic and other hierarchical trees. While version 4 is the actively developed major release, ETE 3.1.3 is the last stable version of the 3.x series, primarily receiving maintenance updates. It offers a comprehensive API for tree handling, node annotation, and customizable tree drawing into various image formats.
Common errors
-
ImportError: cannot import name TextFace
cause This usually indicates a problem with the PyQt or Qt installation, or a conflict between installed `ete3` and `ete3_external_apps` versions, or a missing graphical dependency like `xvfb`.fixEnsure `PyQt5` is correctly installed (`pip install PyQt5` or `conda install pyqt`). If using Conda with `ete_toolchain`, try reinstalling `ete` and `pyqt` together. For headless environments, install `xvfb`. -
ete3 build fails with 'decode_string()' no longer used
cause This error points to a Python version incompatibility, specifically when using Python 3.9+ with older parts of the `ete3` codebase that relied on deprecated `base64` functions.fixDowngrade your Python environment to 3.6, which is the recommended version for full `ete3` and `ete_toolchain` compatibility. Use Conda to create a dedicated environment: `conda create -n ete3_env python=3.6`. -
ete3 evol fails with 'ERROR: model M0 failed, problem with outfile:'
cause This often occurs when `ete3 evol` cannot find or properly execute the external programs (like `codeml`) it depends on, or there are issues with input files (e.g., malformed FASTA, tree without branch lengths).fixVerify that `ete_toolchain` is correctly installed and its components are executable. Check your input FASTA and Newick files for correct formatting. Run `ete3 upgrade-external-tools` to ensure external tools are set up correctly.
Warnings
- breaking ETE 4 (released as `ete4` on PyPI, but also updating the `ete` package) introduced significant breaking API changes from ETE 3. Code written for ETE 3 will not run directly with ETE 4 without modifications.
- deprecated Python 2 support was officially dropped in ETE 3.1.2. While ETE 3.1.0 and 3.1.1 had some Python 3 compatibility, 3.1.2 onward is Python 3-focused. Python 3.6 was specifically recommended for full compatibility with the `ete_toolchain` package. Using newer Python versions (e.g., 3.9+) might encounter issues with older `ete3` components.
- gotcha Graphical features (e.g., `Tree.show()`, `Tree.render()`) in ETE 3 rely on PyQt. Early `ete3` versions had compatibility issues with `PyQt5 >= 5.12`, leading to rendering problems. These were largely addressed in ETE 3.1.3. Conflicts with `PyQt4` and `PyQt5` installations, or missing `xvfb` for headless rendering, are common sources of errors.
- gotcha `ete3-build` and `ete3-evol` commands often require external bioinformatics tools (e.g., MAFFT, FastTree, Codeml) which are not bundled with the core `ete` Python package. These are best installed via the `ete_toolchain` Conda package. Manual compilation or incorrect paths can lead to command failures.
Install
-
pip install ete==3.1.3 -
conda create -n ete3_env python=3.6 conda activate ete3_env conda install -c etetoolkit ete==3.1.3 ete_toolchain
Imports
- Tree
from ete3 import Tree
- PhyloTree
from ete3 import PhyloTree
- TreeStyle
from ete3.treeview import TreeStyle
from ete3 import TreeStyle
- NodeStyle
from ete3 import NodeStyle
- AttrFace
from ete3 import AttrFace
- TextFace
from ete3 import TextFace
Quickstart
from ete3 import Tree, TreeStyle, NodeStyle, TextFace
# Create a tree from a Newick string
t = Tree("((A:1.0,B:1.0):0.5,C:1.5);")
# Print the tree topology to console
print("Tree topology:")
print(t.get_ascii(show_length=True))
# Access nodes and add features
for node in t.traverse():
node.add_features(my_feature="value")
if node.is_leaf():
print(f"Leaf name: {node.name}, feature: {node.my_feature}")
else:
print(f"Internal node: {node.name if node.name else 'Unnamed'}, feature: {node.my_feature}")
# Create a custom tree style
ts = TreeStyle()
ts.show_branch_length = True
ts.show_branch_support = True
ts.show_leaf_name = True
ts.title.add_face(TextFace("My Phylogenetic Tree"), column=0)
# Render the tree to a file (requires PyQt5)
# t.render("my_tree.png", w=600, h=600, tree_style=ts)
# For interactive visualization (requires PyQt5 and an X server/display)
# t.show(tree_style=ts)
print("Quickstart complete. For visualization, uncomment t.render() or t.show() and ensure PyQt5 is installed.")