How should OpenCV 2 be installed on Ubuntu 16.04.5 LTS?

I need OpenCV 2 for a legacy program, specifically OpenCV 2.4.9.1. I have attempted to install python-opencv=2.4.9.1+dfsg-1.5ubuntu1 and libopencv-dev=2.4.9.1+dfsg-1.5ubuntu1. The former appears to install, and when I try to install the latter, having removed its OpenCV 3 equivalent (which has recently become the default), Ubuntu retains some unmet dependency problems which seem to arise from removing OpenCV 3. I have attempted to install libopencv-legacy-dev, which appears to install, but then I am met with the standard OpenCV wrong version error: ImportError: No module named cv2.