Lonesnake
self-contained Python environments with a single command
Install / Use
/learn @pwalch/LonesnakeREADME
lonesnake
lonesnake is a zero-config Bash tool that generates self-contained Python environments with a single command. Each environment fits in a single directory, including a CPython interpreter built from source and a venv. When a capricious environment breaks, you can just delete the directory and generate a new one easily.
It enables you to generate isolated environments not only for projects, but also for global environments or Docker images. It integrates seamlessly with IDEs (VS Code, PyCharm) and dependency management tools (Poetry, pip-tools). It does not impose shell init scripts, so you can activate environments with the method of your choice.
What are the limitations of lonesnake?
- accepts only a single interpreter version per project and per global environment
- supports CPython 3.7+ but not older CPython versions nor alternative interpreters like Pypy
- runs on macOS and Linux, but not Windows
- consumes more disk space than tools that store interpreters in a centralized location
I designed lonesnake to be much easier to understand for the average developer than the centralized tools out there. I deliberately renounced many features to keep the code structure simple. But if lonesnake is too basic for you, feel free to adopt the well-established pyenv or asdf.
installation
macOS installation with Brew
- Step 1:
brew tap pwalch/lonesnake - Step 2:
brew install lonesnake
Linux installation with package manager and curl
<details> <summary>Step 1: install the CPython build dependencies and <code>curl</code>, depending on your OS</summary># The instructions below are taken from the pyenv Wiki and the python.org dev guide.
# Please check them out if you need more details or if you are using a different OS.
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
# https://devguide.python.org/setup/#install-dependencies
# Ubuntu/Debian/Mint
sudo apt-get update && sudo apt-get install -y \
make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev \
libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
# Fedora
sudo dnf install \
curl make gcc zlib-devel bzip2 bzip2-devel readline-devel \
sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel
# Arch Linux
sudo pacman -S --needed curl base-devel openssl zlib xz
</details>
<details>
<summary>Step 2: download <code>lonesnake</code> to <code>~/.local/bin</code></summary>
mkdir -p ~/.local/bin && \
curl -sL -o ~/.local/bin/lonesnake https://raw.githubusercontent.com/pwalch/lonesnake/1.2.0/lonesnake && \
chmod u+x ~/.local/bin/lonesnake
- make sure you have
export PATH="$HOME/.local/bin:$PATH"in your.bashrc(Bash) or.zshrc(ZSH), and open a new shell - check that the script is accessible with
lonesnake --help
usage
example commands
lonesnake- generates an environment with the latest CPython version, in the
.lonesnakedirectory at the root of the current working directory
- generates an environment with the latest CPython version, in the
lonesnake --py 3.13- same, but with the latest patch of CPython 3.13
lonesnake --py 3.13.0- same, but with exactly CPython 3.13.0
If the .lonesnake directory already exists, lonesnake asks for confirmation before deleting it.
automated activation
project activation with direnv
To activate a lonesnake environment when entering a project directory, you can bring your own shell auto-load tool. If you are undecided, I recommend direnv.
<details> <summary>install <code>direnv</code> and register its hook</summary># macOS
brew install direnv
# Ubuntu/Debian/Mint
sudo apt-get install direnv
# Fedora
sudo dnf install direnv
# Archlinux
sudo pacman -S direnv
- Bash: in your
~/.bashrc, appendeval "$(direnv hook bash)" - ZSH: in your
~/.zshrc, appendeval "$(direnv hook zsh)"
- start a new shell then
cd YOUR_PROJECT lonesnake- touch
.envrcthen fill it with this code
# lonesnake auto-activation for the project directory
lonesnake_dir="${PWD}/.lonesnake"
PATH_add "${lonesnake_dir}/venv/bin"
export VIRTUAL_ENV="${lonesnake_dir}/venv"
# Solve errors involving "Python.h not found" when building
# Python extensions with a lonesnake environment.
parent_include_dir="${lonesnake_dir}/interpreter/usr/local/include"
if [[ -d "$parent_include_dir" ]]; then
include_dir_name=$(find "$parent_include_dir" \
-mindepth 1 -maxdepth 1 -type d -name "python3.*" \
-exec basename {} \;)
path_add CPATH "${parent_include_dir}/${include_dir_name}"
fi
direnv allow- check that
which pythonprints your project's.lonesnake/venvdirectory
</details>ℹ️ In case of trouble, you can get rid of the lonesnake environment by running
rm -rf .lonesnake .envrcat the root of your project. Make sure to open a new shell for the change to take effect.
Tips
If you have lonesnake-kit, you can use <code>lonesnake-kit project --direnv</code> to automatically populate .envrc.
# Print direnv activation instructions for lonesnake
# Usage: lonesnake-print-activation >> .envrc
function lonesnake-print-activation() {
cat << EOM
# lonesnake auto-activation for the project directory
lonesnake_dir="\${PWD}/.lonesnake"
PATH_add "\${lonesnake_dir}/venv/bin"
export VIRTUAL_ENV="\${lonesnake_dir}/venv"
# Solve errors involving "Python.h not found" when building
# Python extensions with a lonesnake environment.
parent_include_dir="\${lonesnake_dir}/interpreter/usr/local/include"
if [[ -d "\$parent_include_dir" ]]; then
include_dir_name=\$(find "\$parent_include_dir" \
-mindepth 1 -maxdepth 1 -type d -name "python3.*" \
-exec basename {} \;)
path_add CPATH "\${parent_include_dir}/\${include_dir_name}"
fi
EOM
}
</details>
<details>
<summary>To show a prefix in your shell prompt indicating an active lonesnake venv (e.g. <code>🐍venv-3.13.0</code>), take inspiration from this example code for your <code>~/.bashrc</code> or <code>~/.zshrc</code>.</summary>
show_lonesnake_venv_prefix () {
local cpython_path="$PWD/.lonesnake/venv/bin/python"
# If the venv is activated, print the prompt prefix
if [[ -x "$cpython_path" ]] && \
[[ "$(which python)" == "$cpython_path" ]]; then
local cpython_version="$(python --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')"
echo "🐍venv-${cpython_version} "
fi
}
PS1='$(show_lonesnake_venv_prefix)'"$PS1"
</details>
project dependency management
Provided you have configured direnv as in the previous section, dependency management tools integrate seamlessly into lonesnake venvs.
pip-tools' sync command installs packages in the current venv. Therefore, all packages are installed in the .lonesnake venv directory by default:
cd YOUR_PROJECTpip install pip-toolspip-sync PINNED_COMPILED_REQUIREMENTS
You can integrate Poetry into the .lonesnake directory by specifying the POETRY_VIRTUALENVS_PATH environment variable:
cd YOUR_PROJECT(where yourpyproject.tomlis)- append the following to your
.envrc:
export POETRY_VIRTUALENVS_PATH="${PWD}/.lonesnake/poetry_virtualenvs"
direnv allowpip install poetrypoetry install- check with
poetry debugthat the "Virtualenv Path" is in a child directory of.lonesnake/poetry_virtualenvs
Tips
If you have lonesnake-kit, note that <code>lonesnake-kit project --direnv</code> populates the Poetry environment variables in .envrc.
</details>ℹ️ In case of trouble, you can get rid of the Poetry virtualenvs using
rm -rf .lonesnake/poetry_virtualenvs. Make sure to open a new shell for the change to take effect.
project IDE support
<details> <summary>Visual Studio Code (VS Code)</summary>Auto-Activation:
- open a project directory that contains a lonesnake environment at its root
- click
File > Preferences > Settingsand then go toWorkspaceand search forpython.defaultInterpreterPath - set this path to
${workspaceFolder}/.lonesnake/venv/bin/python - press
CMD/CTRL + SHIFT + Por clickView > Command Palette, then choosePython: Select Interpreter - choose
Use Python from `python.defaultInterpreterPath` setting- note that after the word
setting, you should see./.lonesnake/venv/bin/python
- note that after the word
- when you open the integrated terminal, VS Code should now be sourcing
.lonesnake/venv/bin/activate
File Exclusion:
- click
File > Preferences > Settingsand then go toUserand search forfiles.exclude - click
Add Patternand register**/.lonesnake
If you have lonesnake-kit, note that <code>lonesnake-kit project --vscode</code> populates the settings.json of the workspace in the working directory.
- open a project directory that contains a lonesnake environment at its root
- click
File > Settings > Project: YOUR_PROJECT > Python Interpreter - click
Add Interpreter > Add Local Interpreter... - in
Virtualenv Environment- set
EnvironmenttoExisting - as
Interpreter, pick.lonesnake/venv/bin/pythonfrom your project - click
OK
- set
- click
OK, then wait for the environment to be indexed
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
104.6kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
model-usage
345.4kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
