Date Created: 2025-05-10
By: 16BitMiker
[ BACK.. ]
I'm setting this up on a Mac Studio with the M2 Ultra chip and 96GB of RAM—plenty of horsepower for local language models, multi-process batch jobs, and AI-driven terminal tools like ShellGPT. While the hardware is more than capable, the software setup—especially with Python—can be trickier than expected.
This guide documents how I installed and configured ShellGPT on macOS using Homebrew Python 3.13, following best practices that respect modern Python standards like PEP 668. If you're running a similar setup, this walkthrough should help you avoid the common pitfalls and get up and running smoothly.
After installing Python 3.13.3 via Homebrew, I ran into a familiar but frustrating issue:
pip install shell-gpt
# -> zsh: command not found: pip
At first, it looked like something had gone wrong with the Python install. But after digging in, I found that everything was working as expected—just not the way it used to.
Here’s what was going on:
Python 3.13.3 was correctly installed via Homebrew.
The system followed PEP 668, which now marks Python environments as “externally managed.”
That means pip is intentionally disabled in these environments to prevent accidental conflicts with system-managed packages.
This change is part of a broader shift in the Python ecosystem toward better isolation and more predictable environments. Let’s dig into that.
PEP 668—titled “Marking Python base environments as externally managed”—introduces a safeguard into Python distributions. Authored by Brett Cannon, Tzu-ping Chung, and Steve Dower, the proposal was accepted in late 2021 and implemented in recent Python versions, including the one provided by Homebrew.
The idea is simple: system-managed Python should not be directly modified using pip. Instead, users are encouraged to install packages in isolated virtual environments or use tools like pipx. This prevents a common class of problems where pip installations accidentally overwrite or conflict with packages managed by the system package manager (like apt, dnf, or Homebrew).
When PEP 668 is active, pip will not install packages globally unless you're in a virtual environment or explicitly bypass the restriction (which is strongly discouraged). The mechanism is a special marker file named EXTERNALLY-MANAGED inside the Python installation directory.
In Homebrew’s case, the file contains this message:
xThis Python installation is managed by Homebrew.
The Python core team and Homebrew maintainers strongly advise against
installing Python packages directly with pip, as it can cause conflicts
with package management systems and potentially break system tools.
Instead, please use one of the following approaches:
1. Create a virtual environment:
python -m venv myenv
source myenv/bin/activate
pip install package
2. Install packages for the current user only:
pip install --user package
3. Use a tool like pipx for isolated application installation:
brew install pipx
pipx install package
So instead of trying to force pip to behave the old way, we’re going to do it right—with pipx.
The modern, recommended approach uses pipx to install Python applications in isolated environments, while still making them globally accessible from your terminal. This method:
Fully respects PEP 668 guidelines
Keeps your system Python clean and conflict-free
Creates a dedicated virtual environment for each app
Makes the command available globally via your PATH
Minimizes maintenance headaches down the road
Let’s walk through the setup.
Start by installing pipx using Homebrew:
xxxxxxxxxx
brew install pipx
Then configure your shell’s PATH to include pipx’s binary directory:
xxxxxxxxxx
pipx ensurepath
After running this, pipx will let you know if your shell config file (like ~/.zshrc
) needs manual updating. Apply any suggested changes and reload your shell:
xxxxxxxxxx
source ~/.zshrc
Now use pipx to install ShellGPT (sgpt):
xxxxxxxxxx
pipx install shell-gpt
You should see a confirmation like this:
xxxxxxxxxx
installed package shell-gpt 1.4.5, installed using Python 3.13.3
These apps are now globally available
- sgpt
done! ✨ 🌟 ✨
This installs ShellGPT in its own isolated environment and makes the sgpt command available globally—no need to activate anything.
To enable tab-completion for pipx and other CLI tools:
xxxxxxxxxx
pipx install argcomplete
Then add the following snippet to your .zshrc
file:
xxxxxxxxxx
# pipx completions
autoload -U compinit && compinit
autoload -U bashcompinit
bashcompinit
eval "$(register-python-argcomplete pipx)"
Apply the changes:
xxxxxxxxxx
source ~/.zshrc
ShellGPT needs an OpenAI API key. You can set it up one of two ways:
On first run, ShellGPT will prompt you for your key.
Or, you can export it via your shell config file:
xxxxxxxxxx
echo 'export OPENAI_API_KEY="your-api-key-here"' >> ~/.zshrc
source ~/.zshrc
ShellGPT offers terminal integration that adds keyboard shortcuts like Ctrl+L for AI-powered suggestions:
xxxxxxxxxx
sgpt --install-integration
Then restart your terminal or reload your shell config:
xxxxxxxxxx
source ~/.zshrc
ShellGPT supports several flags to tailor its output to your workflow. Here are some practical examples that demonstrate its versatility:
xxxxxxxxxx
sgpt "How do I find duplicate files in a directory?"
Use the --code flag to generate syntax-highlighted scripts:
xxxxxxxxxx
sgpt --code "Write a Python script to extract data from a CSV file"
Use the --shell flag when you want concrete terminal commands:
xxxxxxxxxx
sgpt --shell "Find all images larger than 5MB and compress them"
Use the --markdown flag to format output for README files, docs, or blog posts:
xxxxxxxxxx
sgpt --markdown "Summarize the pros and cons of using SQLite vs PostgreSQL"
If you have access to GPT-4o’s multimodal capabilities:
xxxxxxxxxx
sgpt --vision "Analyze this network diagram (network.png) for vulnerabilities"
ShellGPT can chain commands to accomplish multi-step tasks:
xxxxxxxxxx
sgpt "Find all .log files modified in the last 7 days and compress them"
Specify the model explicitly for faster or more capable responses:
xxxxxxxxxx
sgpt --model gpt-3.5-turbo "Explain how virtual memory works"
sgpt --model gpt-4 "Generate a bash script that syncs two directories"
Using pipx to install ShellGPT offers several advantages:
✅ Complies with PEP 668 and Homebrew’s Python restrictions
✅ Keeps the base Python installation clean
✅ Enables global command-line access without activating environments
✅ Avoids dependency conflicts between CLI tools
✅ Makes updates simple with pipx upgrade
In short, it's the right way to install Python-based CLI tools in 2025.
If something doesn’t work as expected, here are a few quick checks:
Command not found: Make sure ~/.local/bin
is in your PATH
xxxxxxxxxx
echo $PATH | grep -q ~/.local/bin || echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
API key not recognized: Double-check that OPENAI_API_KEY
is set
xxxxxxxxxx
echo $OPENAI_API_KEY
Shell integration missing: Ensure the integration code is included in your .zshrc
Slow responses: Try using GPT-3.5 instead of GPT-4 for faster replies
xxxxxxxxxx
sgpt --model gpt-3.5-turbo "Quick git tip"
Keep things up to date with:
xxxxxxxxxx
# Upgrade ShellGPT
pipx upgrade shell-gpt
# See all pipx-installed tools
pipx list
# Uninstall if needed
pipx uninstall shell-gpt
With 96GB of RAM, you can do more than just run API-based tools:
🧠 Use local models via Ollama:
xxxxxxxxxx
brew install ollama
ollama pull codellama
echo 'export USE_LITELLM=true' >> ~/.zshrc
🧵 Run parallel queries:
xxxxxxxxxx
batch_sgpt() {
for query in "$@"; do
sgpt "$query" &
done
wait
}
📊 Process large datasets with AI-assisted Python:
xxxxxxxxxx
sgpt --code "Write a Python script to analyze a 50GB CSV efficiently"