Banner - AI Quest
Setting up AI Libraries on Mac: A Step-by-Step Guide

In this tutorial, we’re going to install a range of libraries to get your AI experiments up and running. This includes integrations for frontier models like OpenAI, Claude, and Gemini, the open-source platform Hugging Face, LangChain, and a few others. Once everything is installed, we’ll run through a quick verification to make sure your setup is working correctly.

In a follow-up post, we’ll dive into running additional examples and using LangChain to combine frontier and open-source models – giving you the best of both worlds in your AI experiments.

All the code and examples we’ll cover are available in my GitHub repo, so you can follow along, tweak, and experiment to your heart’s content.

This tutorial is inspired by Ed Donner’s excellent Udemy course LLM Engineering: Master AI, Large Language Models & Agents. Honestly, Ed’s course is fantastic—clear, hands-on, and highly engaging. If you’re starting your AI journey and want to go beyond surface-level buzzwords, I can’t recommend it enough.

Now, a quick confession: while Ed sets things up using conda, I ran into some hiccups getting Hugging Face models to play nicely with Apple Silicon on my M4 Mac. After a fair bit of trial, error, and mild frustration, I found that venv gave me more fine-grained control over packages and let me fully tap into the hardware. Lesson learned: sometimes the “boring” tool turns out to be the hero of the day.

Isolating Python Environments

I’m a big believer in keeping projects neat and organized – every project gets its own little sandbox of libraries. Back in the day, I relied on virtual machines for this, but when it comes to AI work, that extra layer of virtualization just gets in the way. You want your code talking directly to the hardware – not hopping through hoops.

Python gives us several ways to handle virtual environments – there’s the built-in venv, the popular virtualenv, and a few others. The problem with using them as standalone tools is that they can only manage environments for the Python version they were created with. Translation: if you want multiple versions, you have to track them down and install each one manually – not exactly fun.

Fortunately, there’s a very handy library called pyenv that can handle all the heavy lifting for us. It even has a plugin that leverages venv behind the scenes, letting us create virtual environments for any Python version we want – clean, flexible, and hassle-free.

pyenv Setup and Library Install

Setting up pyenv is pretty straightforward. You will need to have Homebrew installed first. If you don’t have it on your macOS yet, you can follow the instructions for setting it up here.

Once that’s ready, installing pyenv is simple – just run these commands:

brew update
brew install pyenv pyenv-virtualenv

After pyenv is installed, you’ll need to add a couple of lines to your .zshrc or .bash_profile file (adjust depending on the shell you use):

echo 'eval "$(pyenv init -)"' >> ~/.zshrc
echo 'if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi' >> ~/.zshrc

Next, let’s grab the repository containing all our library dependencies and navigate to the right path:

git clone https://github.com/miechus/aiupskillquest.git
cd aiupskillquest

We’re now ready to create our first virtual environment – we’ll use Python 3.11.13. You can see we are providing the Python version as the second argument when creating the environment.

pyenv install 3.11.13
pyenv virtualenv 3.11.13 ai-labs

You can switch to the newly created environment in a couple of ways. The local command creates an environment file in the current directory and opens the environment shell. The shell command just opens the shell for the environment without creating the file. The difference? Using local means next time you open a shell in that directory, it automatically switches to that environment.

# use either
pyenv local ai-labs
# or
pyenv shell ai-labs

You’ll notice the shell prompt now has the environment name as a prefix – this means you’re running inside your environment:

(ai-labs) miechus@Mac ai-labs %

Finally, we’re ready to install the Python libraries. We’ll use the dependency list from the repo you just downloaded – it has everything you need to set up your Mac:

pip install -r virtual-environments/ai-labs/requirements-macos.txt

The installation will take a little time, so hang tight. Once it’s finished, we’ll move on to validate that everything is working as expected.

Validating Your Setup

We’ll kick things off by launching JupyterLab, which we’ll use to run our validation tests. If Jupyter isn’t your favorite environment, no worries—you can just as easily use an IDE like Visual Studio Code or anything else that supports Jupyter Notebook files. The key is having a workspace where you can execute cells and see outputs as we go.

jupyter lab notebooks/setup-validation/macos-validation.ipynb

Running this command should bring up a browser window with the Jupyter notebook open.

Click on the first cell in the notebook – the one with the Python imports—and run it by pressing Command + Return. If everything is set up correctly, you’ll see the message Import complete appear just below the cell. That’s your green light to move forward.

Don’t worry if you see a warning – that’s completely normal. Now let’s make sure PyTorch can properly recognize your Mac hardware. Go ahead and run the next two cells in sequence to validate the setup.

You should now see that the hardware has been successfully detected as mps (Metal Performance Shaders), and the second cell produced an output. This confirms that PyTorch is working as expected.

Next, we’ll move on to validating JAX. Run the final two cells in sequence to complete the check. Just like before, you may see a few warnings pop up – these are completely normal and nothing to worry about.

If you see an array of 10 elements, congratulations! You’ve officially completed your macOS setup. Your environment is now ready for local AI experimentation, and you can start exploring what your hardware is truly capable of. Time to dive in and put your setup to work!

Leave a Reply

Discover more from AI Upskill Quest

Subscribe now to keep reading and get access to the full archive.

Continue reading