Installing a Python Package for a Single User

Normally when installing a package that I'm working on I'm using a virtualenv so it's installed within that environment only, but I wanted to test part of my code that was using ssh to run a command that I didn't want to install system-wide. Creating a virtualenv for the test-user and activating it before running the command via ssh seemed excessive (and maybe not possible - I didn't try) but it turns out that you can install packages at the user-level using the 'setup.py' file.

In this case I wanted the setup.py to create a command-line command called 'rotate' and install it in the user's ~/bin folder so I could run it something like this:

ssh test@localhost rotate 90

First I changed the .bashrc to add the bin folder to the PATH:

PATH=$HOME/bin:$PATH

 This has to be added to the top of the .bashrc file because the first thing there by default is a conditional that prevents it from using the things in the .bashrc file:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;

esac

Next I changed into the directory where the package's setup.py file was and installed the package:

python setup.py install --install-scripts=$HOME/bin --user

The --user option is what tells python to install it for the local user instead of /usr/local/bin and the --install-scripts tells it where to put the commands it creates. Without the --install-scripts option it will install it in .local/bin so another option would be to change the PATH variable instead:

PATH=$HOME/.local/bin:$PATH

But I use ~/bin for other commands anyway so it seemed to make more sense to put it there.

OS : Ubuntu 14.04.1 LTS
Python: 2.7.6