Skip to main content

Venv python

Venv python is a small utility to create python and pip executable along with a virtualenv they used. This is meant to to be used with command line scripts.

Motivation

Creating command-line tools is a fairly common act when programming or doing sys admin. In Python, the "accepted" way of doing this is to create a Python project with setuptools and add entrypoints which create executables that can be used from the command line and then install it with pipx. However, this can be a hassle for small or numerous scripts. An alternative way of doing things, is to have Python scripts on your $PATH variables, with one big shared Python environment.

This all worked pretty well until new versions of Ubuntu started preventing you from installing Python packages with pip. The approaches of having "one big shared virtualenv" used by the system and user tools was probably a bad one - but it often worked quite well.

I'm not going to give up using scripts on the my path, so I need a work around. One approach would to be to have my own version of Python that I use with all scripts. However, this felt a bit too wrong. So instead I have a shared version of Python used by each directory on my path.

This utility is defined to used to create these separate Python's.

Installation

Use pipx to install venv-python (in it's own virtualenv)

pipx install venv-python

Usage

If you have a directory on your path which contains python scripts. You can add a Python to it by cd'ing to it and running

venv-python $PREFIX

This will then create python called $PREFIX-python and a pip called $PREFIX-pip.

Then in your python scripts set the hashbang to:

#!/usr/bin/env $PREFIX-python

To install the dependencies of these scripts you can use $PREFIX-pip

Alternatives and prior works

This is obviously just glue code about python virtualenvs. Pipx maintains a virtualenv for a project. You could instead use a single shared Python for all your scripts.

About me

I am @readwithai. I write and make tools to do with reading, productivity often using Obsidian

If you are interested in this tool your might also be interested in:

  1. This blog post about sending code to a virtualenv from within Emacs using Ipython; or
  2. This command-line tool to use numpy from the shell
  3. This library that customizes pdb to be more useable by adding custom commands.

You can follow me on X or my blog

Metadata

Release files for venv-python 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for venv-python 1.0.2
File Size Uploaded
venv-python-1.0.2.tar.gz 4.0 kB Details

Release files / venv-python-1.0.2.tar.gz

Download URL venv-python-1.0.2.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ae5f043321cc0e6a0b9f60cf8db67add9f80fb64ec05eea82546034301a8483c
BLAKE2b-256 checksum
How to use checksums
bdacb176dc58a42ca80e8d81c5e5ff7c170d4e8a13a066f81a6d022384d9d006
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page