Search code examples
pythonpipvirtualenvenvironment

Moving Python venv to another machine without internet


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?


Solution

  • 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