This is a three step process. First, download the required packages on a machine with internet access. Then, copy files over to the server with no internet access using scp or through a bastion host. Finally, run the pip install command to use local files.
pip download -r ./requirements.txt -d "dependencies"
This will download all the required packages to a local folder called
dependencies
# To tar and compress
tar cfvz dependencies.tar.gz dependencies
# or
zip dependencies
# To copy
scp dependencies.tar.gz user@target:/tmp
# Untar / unzip files
tar xfvz dependencies.tar.gz
# Install using pip
pip install --no-index --find-links=/path/to/downloaded_packages -r requirements.txt
--no-index
: Tells pip not to look at PyPI.
--find-links
: Points to the local folder with the downloaded packages.