Installing pyenv - firedrakeproject/firedrake GitHub Wiki
It can be helpful to install Firedrake using a Python executable installed with pyenv rather than a system provided version. This is because:
- When the system Python bumps a minor version (e.g. 3.10 -> 3.11) the Firedrake virtual environment will still work.
- MacOS ships with a broken Python installation and the homebrew version also does not always work.
To install pyenv (assuming MacOS with homebrew installed) one needs to:
- Install build dependencies
- Install pyenv. Note that the pyenv provided by homebrew should not be installed. At the time of writing it unconditionally injects
CFLAGS
andLDFLAGS
that will break components like petsc4py and mpi4py if you have a homebrew-installed OpenMPI. - Set
PYENV_ROOT
andPATH
$ export PYENV_ROOT=$HOME/.pyenv $ export PATH=$PYENV_ROOT/bin:$PATH
- Initialise the shell
Note that this command is optional. One can instead find the installed Python versions under
$ eval "$(pyenv init -)"
$(pyenv root)/versions
. See here for more information. - Install a Python version (here 3.11)
$ pyenv install 3.11
- Set this Python as the default for this shell (only if using
pyenv init
)$ pyenv shell 3.11
- Run
firedrake-install
,python
will resolve to the correct executable$ python firedrake-install <args>
Note that the above instructions are equivalent to those found here.
You might also find it helpful to install the Firedrake virtual environment in such a way that pyenv can easily find it.
You can do that by adding an argument to the install script:
$ python firedrake-install <args> --venv-name=$(pyenv root)/versions/firedrake
After the installation succeeds, you can activate the Firedrake virtual environment with pyenv shell firedrake
.