How to install Python packages and dependencies offline
Introduction
In this note, I’ve summarized how you can download Python packages and quickly install them offline on other machines. Although the instructions are written for Linux, they’re fairly easy to apply to Windows as well. Ensure that the same Python version is installed on all machines—I tested this with Python versions 3.10 and 3.11.
Requirements
The Python package manager, pip
, is used for installing and updating packages within a virtual environment.
The Python installers for macOS and Windows include pip. On Linux, you may need to install an additional package, such as python3-pip
. To ensure pip is up-to-date, you can run:
How To
Download packages
In this example, I’m going to create a requirements file and download the following packages:
-
Go to the folder where you want to download the packages, create
requirements.txt
and add the following packages:Jinja2
is used as an example to indicate that it must be above a certain version, an exact version is also possible:Jinja2==2.5.5
. -
Run the following command to download the packages and dependencies:
Now the packages are downloaded, also notice that
MarkupSafe
is downloaded as dependency ofNinja2
. The Python version (in my case 3.11) is often mentioned in the filenames likecp311
.
Install packages offline
Without virtual environment
-
Copy the folder with the packages (
whl
files) andrequirements.txt
to another machine with the same Python version -
Go to the folder and run the following command to install the packages:
Now the packages are installed.
With virtual environment
In the case of a virtual environment with it’s own independent set of packages, the steps are:
-
Create a virtual Python installation in the
my-venv
folder: -
Before you can start installing or using packages in your virtual environment you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific
python
andpip
executables into your shell’s PATH: -
Install the packages:
Now, the packages are installed in the virtual environment.
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.