Installing Python packages on offline systems

Introduction

Parnika J
2 min readFeb 22, 2024

In today’s digital age, connectivity is often taken for granted. However, there are scenarios where internet access is limited or unavailable, posing challenges for installing essential tools like Python packages. Whether working in remote locations, secure environments, or on air-gapped systems, let's explore the steps to overcome these obstacles and ensure smooth Python package installations. Drawing from experience, I’ve found a simple yet effective approach to installing Python packages offline. Let’s walk through the process step by step.

Setup

Understanding the Setup:
Imagine three distinct systems at play:
1. An online system with internet connectivity.
2. An offline system where packages need installation.
3. An additional system acting (optional).

Initial Setup and Preparation
Commence by noting the Python version and operating system of both the online and offline systems. This foundational step guides subsequent actions.

First Approach: Matching Python Version and OS

If the online system mirrors the offline system in Python version and Operating System (OS), proceed as follows:

On the Online System:
1. Establish a designated folder for package downloads.
2. Copy the folder path for future reference.
3. Utilize the following Python command to initiate package downloads:

py -pythonVersion -m pip download packageName -d”FolderPath”

This command fetches .whl files for the specified package and its dependencies, tailored to the offline system’s specifications.

For example:
py -3.11 -m pip download ultralytics -d”C:/PackageFolder”

On the Offline System:
1. Execute the following commands for each downloaded dependency:

py -pythonVersion -m pip install dependency1.whl
py -pythonVersion -m pip install dependency2.whl

Continue this process for each dependency, seamlessly integrating them into the offline environment. But, to avoid doing this for every package, list the names of the packages along with their extensions in a notepad (text file). Name this text file as requirements.txt and run the following command:

pip install -r requirements.txt — find-links=C:/PackageFolder — no-index

Second Approach: Differing Python Version or OS

In cases where the online system differs in Python version or operating system, follow this alternative approach:

On an Additional System:
1. Utilize the first approach to identify and list all necessary dependencies and their versions. You can also use the online system.

On the Online System:
1. Manually download each dependency with the correct version and OS from the Python Package Index website (https://pypi.org/).

On the Offline System:
1. Refer back to the first approach’s instructions to install the downloaded packages, ensuring a smooth installation process despite differing system configurations.

Conclusion

Based on firsthand experience, I’ve discussed an approach for installing Python packages offline. By understanding system requirements and employing intermediary steps, one can efficiently manage dependencies, facilitating seamless project execution regardless of internet accessibility.

--

--