Skip to content

Tutorial 10

Lee Burton edited this page Jul 15, 2025 · 21 revisions

๐Ÿ Python Virtual Environments

This guide will help you set up a Python Virtual Environment (PVE) on both:

  • ๐Ÿ’ป Your Mac
  • โš™๏ธ The POWER cluster

By the end, you'll have an isolated and clean Python environment running smoothly on both machines. ๐ŸŽฏ


๐ŸŽ PVE on Your Mac

First, open your Terminal and install Homebrew, a package manager that makes software installation easy:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

๐Ÿ‘€ You'll be prompted to add some lines to your shell's PATH. Follow the on-screen instructions.


๐Ÿบ Install GCC (includes gfortran)

This will be useful later, especially for scientific Python packages:

brew install gcc

๐Ÿ Install Micromamba

Micromamba is a fast and lightweight package and environment manager. Install it via Homebrew:

brew install micromamba

Once installed, you'll again be prompted to add Micromamba to your shell:

/opt/homebrew/opt/micromamba/bin/micromamba shell init -s zsh -p ~/micromamba

๐Ÿง™โ€โ™‚๏ธ Make Your Life Easier with an Alias

To simplify usage, alias mamba to micromamba:

  1. Open your zprofile file:

    vim ~/.zprofile
  2. Add this line to the bottom:

    alias mamba="micromamba"

๐Ÿ’ก Now you can use mamba commands on both your Mac and the POWER cluster with the same syntax!


โšก PVE on POWER

Letโ€™s configure your virtual environment on the POWER cluster. ๐Ÿ’ช

๐Ÿงพ Modify .bashrc

Add this line to the end of your .bashrc file:

module load mamba > /dev/null

Then apply the change:

source ~/.bashrc

โœ… Youโ€™re now ready to create environments with Mamba on POWER!


๐Ÿ—๏ธ Creating a Virtual Python Environment

Run the following command (replace <youraccountname> with your username):

mamba create --prefix /leeburton-data/<youraccountname>/envs/my_env python=3.8

๐ŸŽฏ Itโ€™s important to use Python 3.8 โ€” later tools like USPEX depend on it.


๐Ÿš€ Activate the Environment

mamba activate /bmd/<youraccountname>/envs/my_env

You'll now see the environment name in your terminal prompt. ๐ŸŸข


๐Ÿ“ฆ Install Required Packages

Inside the environment, install these useful Python modules:

mamba install spglib
mamba install ase
mamba install numpy
mamba install scipy

Each module plays a role in atomic simulations and numerical operations.


๐Ÿ“ด Deactivate the Environment

When you're done:

mamba deactivate

๐Ÿ” You can reactivate the same environment anytime using the mamba activate command again.


๐ŸŽ‰ All Set!

You now have working Python virtual environments on both your Mac ๐Ÿ and the POWER cluster โš™๏ธ. Enjoy clean and reproducible scientific computing!

โžก๏ธ Move on to Tutorial 11 for the next step in your journey! ๐Ÿš€

Clone this wiki locally