Back to Blog
PythonBiopython

Install Biopython in a conda Environment (macOS, Apple Silicon)

Install Biopython in an isolated conda environment on Apple Silicon, verify the native arm64 build, and parse a FASTA file with SeqIO.

SSSudipta SardarJuly 20, 20267 min read
Install Biopython in a conda Environment (macOS, Apple Silicon)

Biopython is the standard-library equivalent for computational biology in Python: it parses sequence file formats, talks to NCBI databases, wraps command-line tools like BLAST, and gives you a consistent Seq object instead of another hand-rolled FASTA parser. If you are learning bioinformatics in Python, it is usually one of the first packages you install, right alongside NumPy and pandas.

This guide installs Biopython into its own isolated conda environment on an Apple Silicon Mac, using the native arm64 build from conda-forge. As with every install guide in this series, the goal is a throwaway, reproducible environment: if something breaks, delete it and rebuild in under a minute, with zero effect on the rest of your system.

Why Biopython deserves its own environment

Biopython itself is a lightweight, mostly pure-Python package, but it sits on top of NumPy and can pull in optional extras like reportlab if you ask for graphics support. The real reason to isolate it is not weight, it is reproducibility: a script built around Bio.SeqIO should not be at the mercy of whatever else later gets installed into a shared base environment. Give it a dedicated env, and an exported environment.yml next to your script fully describes what it needs to run.

Prerequisites

You need a working conda installation. If you do not have one yet, start with our Miniconda on Apple Silicon guide and come back here. Everything below assumes an Apple Silicon Mac (arm64) with a recent conda release using the fast libmamba solver, which has been the default solver since conda 23.10.

TL;DR: copy-paste install

bash
conda create -n bu-biopython --override-channels -c conda-forge biopython -y
conda activate bu-biopython
python -c 'import Bio; print(Bio.__version__)'

Three things to notice in that one line: an isolated env named bu-biopython, --override-channels so conda never touches the Anaconda defaults channel (which trips a Terms-of-Service gate on recent conda versions), and just -c conda-forge, since Biopython is a conda-forge package rather than a bioconda one.

Step-by-step

1. Create an isolated environment

bash
conda create -n bu-biopython --override-channels -c conda-forge biopython -y

A couple of things worth understanding here:

  • --override-channels -c conda-forge restricts the solve to conda-forge only. Skipping defaults entirely sidesteps the CondaToSNonInteractiveError Terms-of-Service prompt that recent conda releases throw when they touch the Anaconda default channel.
  • No bioconda needed. Unlike aligners and variant callers, Biopython is a general-purpose Python library and lives on conda-forge, alongside its main dependency, NumPy. You only need -c bioconda here if you plan to add other bioinformatics command-line tools to the same environment later.
  • No version pin. This installs the latest Biopython that conda-forge has published. If you need a specific version for reproducibility, pin it explicitly, for example biopython=1.8*.

When conda solves the environment, you should see something like the following (exact versions and download sizes vary with when you run it):

text
Channels:
 - conda-forge
Platform: osx-arm64
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##
  environment location: /opt/homebrew/Caskroom/miniconda/base/envs/bu-biopython
  added / updated specs:
    - biopython

The following NEW packages will be INSTALLED:
  biopython          conda-forge/osx-arm64::biopython-1.8x-py3xx_0
  numpy               conda-forge/osx-arm64::numpy-2.x.x-py3xx_0
  python              conda-forge/osx-arm64::python-3.xx.x-h...

The osx-arm64 tag on every line is the detail worth checking: it means conda solved a native Apple Silicon build for Biopython, NumPy, and the Python interpreter itself, not an emulated one.

2. Activate and confirm

bash
conda activate bu-biopython

Your shell prompt should now show (bu-biopython). Every command below assumes this environment is active.

Apple Silicon: this is a native arm64 build

Biopython has shipped native osx-arm64 builds for a long time now, so there is no Rosetta 2 fallback to reach for here. You can confirm the interpreter and the package both resolved natively:

bash
conda list -n bu-biopython biopython
file $(python -c 'import sys; print(sys.executable)')

conda list should report the build channel as conda-forge with an osx-arm64 tag, and file should describe the Python binary as arm64. If you later add a bioconda tool that lacks an arm64 build, the documented fallback is a separate x86-64 environment run under Rosetta 2 with CONDA_SUBDIR=osx-64, but you should not need it for Biopython itself.

Verify the install

First, confirm the import works and print the version:

bash
python -c 'import Bio; print(Bio.__version__)'

You should see something like a bare version string, for example:

text
1.8x

That confirms the package imported and the version string looks sane. Now do something Biopython is actually for: parse a FASTA record with SeqIO.

python
from io import StringIO
from Bio import SeqIO

fasta_text = """>seq1 toy example
ATGGCGTACGTTAGC
>seq2 second toy example
ATGCCGTACGGGTAGCTAA
"""

for record in SeqIO.parse(StringIO(fasta_text), "fasta"):
    print(record.id, len(record.seq), record.seq)

You should see something like:

text
seq1 15 ATGGCGTACGTTAGC
seq2 19 ATGCCGTACGGGTAGCTAA

SeqIO.parse returned a SeqRecord for each entry, record.id pulled the identifier from the header line, and record.seq gave you a Seq object you can slice, translate, or reverse-complement like a string. Swap the StringIO object for a real file path (or an open file handle) and the same three lines parse any FASTA file on disk, no format-specific code required.

Biopython also ships Bio.Entrez, a thin wrapper around NCBI's E-utilities for pulling sequences and records directly from GenBank, PubMed, and other NCBI databases. It needs live internet access and a valid email address set via Entrez.email, per NCBI's usage policy, so it is not something to smoke-test in an offline install guide. Worth knowing it exists once you need to fetch records programmatically instead of downloading them by hand.

pip vs conda: which should you use

Biopython installs cleanly from either pip or conda, and both are legitimate choices. The difference is what manages the dependencies around it.

conda install -c conda-forge biopythonpip install biopython
Native arm64 buildYes, prebuilt by conda-forgeYes, via a prebuilt wheel
Manages NumPy for youYes, resolved in the same solveNo, pip installs NumPy separately
Plays well with other conda bio toolsYes, same environment as bioconda packagesMixing pip and conda in one env can cause conflicts
Best whenYou already use conda for other bioinformatics toolsYou are inside a plain venv with no conda involved

The practical rule: if you are already managing a conda environment, which this whole series assumes, install Biopython with conda so it shares one dependency resolver with everything else in that environment. Reach for pip install biopython when you are working in a plain Python virtual environment with no conda involved at all. What you should avoid is mixing the two inside one environment; pip-installing packages on top of a conda-managed NumPy has a long history of producing subtle ABI mismatches.

Common errors and fixes

ErrorFix
CondaToSNonInteractiveError / Terms of Service not accepted for defaultsDo not use the defaults channel. Install with --override-channels -c conda-forge as shown.
PackagesNotFoundError: ... biopythonYou likely added -c bioconda without -c conda-forge, or omitted --override-channels. Biopython lives on conda-forge.
ModuleNotFoundError: No module named 'Bio'You forgot to activate the environment, or installed into the wrong one. Run conda activate bu-biopython and check which python.
ImportError mentioning a NumPy ABI mismatchYou pip-installed a package on top of the conda-managed NumPy. Reinstall NumPy from conda-forge, or start the environment over.
SeqIO.parse returns zero recordsCheck that the format string, "fasta", "genbank", "fastq", matches the actual file, and that the file path or handle is correct.
Bio.Entrez calls hang or raise an HTTP errorConfirm internet access, set Entrez.email, and check you are not being rate-limited; NCBI throttles unregistered API requests.

Managing the environment

Update Biopython in place:

bash
conda update -n bu-biopython --override-channels -c conda-forge biopython

Snapshot the environment so a collaborator, or your future self, can reproduce it exactly:

bash
conda env export -n bu-biopython --no-builds > biopython-env.yml

And remove it cleanly when you are done. Because everything lived inside the environment, this leaves no trace on the rest of your system:

bash
conda remove -n bu-biopython --all

Next steps

Biopython is connective tissue for a lot of downstream work. A couple of natural follow-ons: