Skip to main content

Create a specially named python and pip for use with scripts

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

venv-python-1.0.2.tar.gz (4.0 kB view details)

Uploaded Source

File details

Details for the file venv-python-1.0.2.tar.gz.

File metadata

  • Download URL: venv-python-1.0.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for venv-python-1.0.2.tar.gz
Algorithm Hash digest
SHA256 ae5f043321cc0e6a0b9f60cf8db67add9f80fb64ec05eea82546034301a8483c
MD5 ae3a7b7dcd6038a22142976c24c7eef0
BLAKE2b-256 bdacb176dc58a42ca80e8d81c5e5ff7c170d4e8a13a066f81a6d022384d9d006

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page