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