GNU/Linux & macOS#
Prerequisites#
To use PyBaMM, you must have Python 3.8, 3.9, 3.10, 3.11, or 3.12 installed.
To install Python 3 on Debian-based distributions (Debian, Ubuntu, Linux Mint), open a terminal and run
sudo apt update
sudo apt install python3
On Fedora or CentOS, you can use DNF or Yum. For example
sudo dnf install python3
On macOS, you can use the homebrew
package manager. First, install
brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
then follow instructions in the link on adding brew
to path, and run
brew install python3
Install PyBaMM#
User install#
We recommend to install PyBaMM within a virtual environment, in order
not to alter any distribution Python files.
First, make sure you are using Python 3.8, 3.9, 3.10, 3.11, or 3.12.
To create a virtual environment env
within your current directory type:
virtualenv env
You can then “activate” the environment using:
source env/bin/activate
Now all the calls to pip described below will install PyBaMM and its
dependencies into the environment env
. When you are ready to exit
the environment and go back to your original system, just type:
deactivate
PyBaMM can be installed via pip. On macOS, it is necessary to install the SUNDIALS library beforehand.
In a terminal, run the following command:
pip install pybamm
In a terminal, run the following commands:
brew install sundials
pip install pybamm
PyBaMM’s required dependencies (such as numpy
, casadi
, etc) will be
installed automatically when you install PyBaMM using pip
.
For an introduction to virtual environments, see (https://realpython.com/python-virtual-environments-a-primer/).
Optional - scikits.odes solver#
Users can install scikits.odes to utilize its interfaced SUNDIALS ODE and DAE solvers wrapped in PyBaMM.
Note
Currently, only GNU/Linux and macOS are supported.
Note
The scikits.odes
solver is not supported on Python 3.12 yet. Please refer to bmcage/odes#162.
There is support for Python 3.8, 3.9, 3.10, and 3.11.
In a terminal, run the following commands:
apt-get install libopenblas-dev
pip install wget cmake
pybamm_install_odes
system (under ~/.local
), before installing scikits.odes
. (Alternatively, one can install SUNDIALS without this script and run pip install pybamm[odes]
to install pybamm
with scikits.odes
.)
In a terminal, run the following command:
brew install openblas gcc gfortran
pip install wget cmake
pybamm_install_odes
The pybamm_install_odes
command, installed with PyBaMM, automatically downloads and installs the SUNDIALS library on your
system (under ~/.local
), before installing scikits.odes . (Alternatively, one can install SUNDIALS without this script and run pip install pybamm[odes]
to install pybamm
with scikits.odes)
To avoid installation failures when using pip install pybamm[odes]
, make sure to set the SUNDIALS_INST
environment variable. If you have installed SUNDIALS using Homebrew, set the variable to the appropriate location. For example:
export SUNDIALS_INST=$(brew --prefix sundials)
Ensure that the path matches the installation location on your system. You can verify the installation location by running:
brew info sundials
Look for the installation path, and use that path to set the SUNDIALS_INST
variable.
Note: The location where Homebrew installs SUNDIALS might vary based on the system architecture (ARM or Intel). Adjust the path in the export SUNDIALS_INST
command accordingly.
To avoid manual setup of path the pybamm_install_odes
is recommended for a smoother installation process, as it takes care of automatically downloading and installing the SUNDIALS library on your system.
Optional - JaxSolver#
Users can install jax
and jaxlib
to use the Jax solver.
Note
The Jax solver is only supported for Python versions 3.9 through 3.12.
pip install "pybamm[jax]"
The pip install "pybamm[jax]"
command automatically downloads and installs pybamm
and the compatible versions of jax
and jaxlib
on your system. (pybamm_install_jax
is deprecated.)
Uninstall PyBaMM#
PyBaMM can be uninstalled by running
pip uninstall pybamm
in your virtual environment.