Skip to content

Instantly share code, notes, and snippets.

@averycowan
Last active June 14, 2023 20:34
Show Gist options
  • Save averycowan/bbe5f4ab20eb878424b7b8bdb4e79033 to your computer and use it in GitHub Desktop.
Save averycowan/bbe5f4ab20eb878424b7b8bdb4e79033 to your computer and use it in GitHub Desktop.
#!/bin/bash -i
# This script runs python3 from within a virtual environment
# Put this file into the 'bin' folder of your venv
# Set it to the interpreter path
# Script Summary:
# - Launch this script as an interactive bash process
# - Find the venv from $0
# - Activate the venv
# - Display the python3 command to the user
# - Convert this bash process into a python3 process
# Don't pollute the bash history
unset HISTFILE
# Stop if any line fails
set -e
# Activate the venv
# Use the current script's $0 path to find the venv's bin folder
. "`dirname $0`/activate"
# Print the prompt and python command to run
printf '%s' "${PS1@P}" >&2
echo python3 "$@" >&2
# Invoke python3 via exec
# Instead of creating a child process, replace this bash process with python3
exec python3 "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment