Anaconda Python on air-gapped computers
Installing the Anaconda Python distribution on an air-gapped (i.e., non-networked) computer is possible but not trivial. These steps worked for me.
1. Create a local environment under Anaconda that contains the desired packages
$ conda create --name myenv python=3.6.7
$ conda activate myenv
$ conda install pillow pip
Choice of Python version, packages, etc., should match your needs. Ensure that your local installation works as desired before proceeding.
2. Write a list of packages installed in the environment to a text file (spec file)
$ conda list --explicit > /path/for/spec_file.txt
3. Retrieve all of the packages from the remote servers to local storage (e.g., ./pkgs directory)
$ cat /path/for/spec_file.txt | grep "^http" | xargs -I xxx wget -P /path/for/pkgs xxx
4. Edit the spec file so that it references your local pkgs directory
I found that the following format and directory structure made things simpler:
$ cat spec_file.txt
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
@EXPLICIT
pkgs/pillow-6.2.1-py36hd70f55b_1.tar.bz2
pkgs/python-3.6.7-h357f687_1006.tar.bz2
pkgs/pip-19.3.1-py36_0.tar.bz2
$ tree .
.
├── pkgs
│ ├── pillow-6.2.1-py36hd70f55b_1.tar.bz2
│ ├── pip-19.3.1-py36_0.tar.bz2
│ └── python-3.6.7-h357f687_1006.tar.bz2
└── spec_file.txt
5. Download the latest Miniconda
From https://docs.conda.io/en/latest/miniconda.html
6. Put spec file, packages, and Miniconda installer on a USB drive
7. Copy files from USB drive to air-gapped computer
8. Install Miniconda
Use the Windows installer or bash Miniconda3-latest-Linux-x86_64.sh
on Linux.
Depending on your installation choices, you may need to open the Anaconda prompt (Windows) or run source ~/.bashrc
(Linux) to access the conda
command in the next step.
9. Create your new environment with the "--file" option pointing to your spec file
$ conda create --name myenv --file /path/to/spec_file.txt
Note that the packages you downloaded must be located at the paths indicated in the spec file (relative paths are fine).
10. Switch to and test the new environment
$ conda activate myenv
$ python test.py