Skip to content

Install Pylectra

Beginner

Prerequisites: Install Python, Install Git, What is a virtual environment

Pick your path

Your goal Recommended path
Just run pylectra, no source edits Path 1: install from PyPI
Track latest code / read internals / patch bugs Path 2: editable source install
Avoid git but want source code Path 3: download zip

All three start from a working Miniconda — see Install Python.

Path 1 — install from PyPI

# 1. Create a clean environment
conda create -n pylectra-env python=3.11 -y
conda activate pylectra-env

# 2. Install pylectra (core)
pip install pylectra

# 3. Recommended: also install the pandapower backend
pip install pylectra[pandapower]

Verify:

python -c "import pylectra; print(pylectra.__version__)"

You should see a version number, e.g. 0.1.0.

Path 2 — editable source install

For users who want to read/modify source or contribute PRs.

# 1. Clone
git clone https://github.com/ZongjiaLong/Pylectra.git
cd pylectra

# 2. Create environment
conda create -n pylectra-dev python=3.11 -y
conda activate pylectra-dev

# 3. Install editable
pip install -e .

# 4. Optional extras
pip install -e ".[dev]"          # pytest / ruff
pip install -e ".[docs]"         # mkdocs documentation build
pip install -e ".[torch]"        # torchdiffeq GPU solvers
pip install -e ".[all]"          # everything (~2 GB)

-e . (editable) magic: edits to source files take effect on the next import pylectra — no reinstall needed.

Path 3 — download zip (no git)

  1. Open the pylectra Releases page.
  2. Pick the latest version, click Source code (zip).
  3. Unzip to a path without spaces or non-ASCII characters.
  4. From a terminal inside that directory:
cd path-to-unzipped/pylectra-0.1.0
conda create -n pylectra-env python=3.11 -y
conda activate pylectra-env
pip install -e .

Verify the install

Regardless of path, run these two:

# 1. Package imports
python -c "import pylectra; print('OK', pylectra.__version__)"

# 2. CLI works
python -m pylectra info

The second command lists every registered plugin — 12 categories, several dozen names. Seeing this means pylectra is fully wired up.

Install extra scientific packages

Subsequent tutorials use:

# conda is more reliable for binary-heavy packages
conda install -c conda-forge numpy scipy matplotlib pandas h5py pyarrow

# pandapower backend (already covered in Path 1; install separately for Path 2/3)
conda install -c conda-forge pandapower

# Jupyter Notebook (optional but very handy for interactive analysis)
conda install -c conda-forge jupyterlab

Smoke test

python -m pylectra run examples/single_case39.yaml

Path 1 users may not have an examples/ directory locally. Either switch to Path 2/3 to grab the source, or pull the YAMLs individually from the GitHub examples folder.

Expected: ~30 s of log output ending with:

[single] simulation completed in X.XX seconds

That's your first successful simulation. Detailed walk-through in Your first simulation.

FAQ

Q: conda create raises an SSL error

Usually a mirror or proxy issue. Try:

conda config --remove-key channels         # Reset to defaults
conda create -n pylectra-env python=3.11

Q: pip install pylectra hangs at "Building wheel for h5py..."

h5py needs the HDF5 C library. Install via conda first:

conda install -c conda-forge h5py
pip install pylectra

Q: pandapower won't install

conda install -c conda-forge pandapower

The conda channel almost always works.

Q: How do I upgrade pylectra?

# Path 1 (PyPI)
pip install --upgrade pylectra

# Path 2 (source)
cd pylectra
git pull
pip install -e .    # only needed if dependencies changed

Q: How do I uninstall completely?

conda activate pylectra-env
pip uninstall pylectra

conda deactivate
conda env remove -n pylectra-env   # remove the whole environment

Next steps