Skip to content

Instantly share code, notes, and snippets.

@jstaursky
Last active July 23, 2020 02:36
Show Gist options
  • Save jstaursky/49fdebc5235c82275c1063a86970b695 to your computer and use it in GitHub Desktop.
Save jstaursky/49fdebc5235c82275c1063a86970b695 to your computer and use it in GitHub Desktop.

How to import locally-made libs in Python

NOTE likely not completely accurate (will update at some point – short on time atm.)

You will want to have a shell wrapper script that containts the following. Where /path/to/script is the path too your python script(s)

#!/usr/bin/env bash
export PYTHONPATH=$PYTHONPATH:/path/to/script

in the python script that wants to use a local python library put

import getopt, sys
sys.path.append("/folder/containing/local-python-lib")

neat way to parse and assign variables inside a shell script

while getopts 'p:o:' arg;
do
    case $arg in
        p)
            OPTION="$OPTARG";;
        o)
            OUTPUT="$OPTARG";;
    esac
done

shift $(($OPTIND-1))

# ...
  
#example usage: <script name> -p <option> -o <output name> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment