2

I am trying to deploy a Python project to a machine with no internet. Because it has no internet, I cannot pip install any packages with a requirements.txt file. I am wondering if it is possible to move my existing environment with all installed packages into another machine with all packages pre-installed.

I can also use attempt to use Docker for this installation. Would I be able to pre-install all the packages within a Docker container and then copy all the files onto another VM?

phd
  • 82,685
  • 13
  • 120
  • 165
Rui Nian
  • 2,544
  • 18
  • 32
  • yes, in most cases virtual environments can be simply copied same is also true for Docker images. It won't work if the hardware problem is different, packages include compiled libraries, and kernel/libs are substantially different across targets. – Marat Mar 13 '22 at 21:43
  • Do you have pip on the remote machine? – Corralien Mar 13 '22 at 21:54
  • I can probably install pip on the remote machine, but it would not have it natively. The remote machine will be a VM running Windows Server 2016. – Rui Nian Mar 13 '22 at 22:02
  • https://stackoverflow.com/a/14447068/7976758 Found in https://stackoverflow.com/search?q=%5Bpip%5D+offline – phd Mar 13 '22 at 22:48

1 Answers1

9

On you local machine (adapt the instructions if you are on Windows)

  1. Create your requirements.txt file
(venv) [...]$ mkdir pkgs
(venv) [...]$ cd pkgs
(venv) [...]$ pip freeze > requirements.txt
(venv) [...]$ pip download -r requirements.txt
  1. Download pip archive from here

  2. Copy pkgs folder to the remote machine

On the remote machine:

  1. Install pip from archive
(venv) [...]$ cd pkgs
# --- unarchive pip.tar.gz ---
(venv) [...]$ python setup.py install
  1. Install packages
(venv) [...]$ pip install --no-index --find-links . -r requirements.txt
Corralien
  • 109,409
  • 8
  • 28
  • 52