Skip to content

Instantly share code, notes, and snippets.

@SeanHood
Last active December 24, 2024 00:50
Show Gist options
  • Save SeanHood/7901d38772f4eb87151329a26bc07c1b to your computer and use it in GitHub Desktop.
Save SeanHood/7901d38772f4eb87151329a26bc07c1b to your computer and use it in GitHub Desktop.
Vendoring Python dependencies for the lazy

Vendoring Python dependencies for the lazy

Say I've written a script in Python and want to ship the whole thing in a single directory/tarball to a machine without having to polute the system by running pip or yum. This is a way to do that.

# Install deps into a directory called vendor
pip install -r requirements.txt --prefix vendor
# This code adds the vendor directory to Python's path so it can find the modules
import os
import sys

parent_dir = os.path.abspath(os.path.dirname(__file__))
vendor_dir = os.path.join(parent_dir, 'vendor/lib/python3.5/site-packages')
sys.path.append(vendor_dir)

That's about it

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment