Skip to content

Instantly share code, notes, and snippets.

@Quar
Created June 14, 2018 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quar/e63c733ce79b12992396a927b511ef70 to your computer and use it in GitHub Desktop.
Save Quar/e63c733ce79b12992396a927b511ef70 to your computer and use it in GitHub Desktop.
Offline Install Python Package with `pip3`

Offline Install Python Package with pip3

Yes you can do it with pip3 (or pip).

And it is simple.

Now we assume you have two computers, both have python3 and pip3 installed, and:

  • hostA has internet connection
  • hostB does not have internet connection

Our task is to download python package from hostA and copy downloads to install packages offline on hostB.

  1. Put all of your required python packages into a requirement.txt file. See more details at https://pip.readthedocs.io/en/1.1/requirements.html Assume your requirement.txt looks like:

    hostA$ ls
    requirements.txt
    hostA$ cat requirement.txt
    pandas
    pip-autoremove
    scikit-learn
  2. Use pip3 to download python packages specified in requirement.txt:

    hostA$ mkdir requirement
    hostA$ ls
    requirements  requirements.txt
    hostA$ pip download -r requirements.txt -d requirements
    Collecting pandas (from -r requirements.txt (line 1))
    ...
  3. Copy both:

    • fie requirement.txt and
    • directory requirement from hostA to hostB.
  4. On hostB, under directory contains both:

    • fie requirement.txt and
    • directory requirement
    hostB$ ls
    requirements  requirements.txt
    hostB$ pip install --no-index --find-link=requirements -r requirements.txt
    Collecting pandas (from -r requirements.txt (line 1))
    ...
    

Tada!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment