This guide explains how to back up Python package dependencies using .whl
(wheel) files from your requirements.txt
. These steps allow you to save the necessary package files and install them later without needing an internet connection.
If you don't already have a requirements.txt
file, create one by freezing your current environment's dependencies:
pip freeze > requirements.txt
This will generate a requirements.txt file with all the currently installed packages and their versions.
- Download .whl Files for All Packages Use the following command to download the .whl files for all the packages listed in requirements.txt:
mkdir packages
pip download -r requirements.txt -d packages/
-r requirements.txt: Specifies the requirements.txt file containing the list of dependencies. -d packages/: Downloads all .whl files into the packages/ directory.
-
Verify the Downloaded .whl Files After running the command, you should see a folder called packages/ containing all the .whl files of the packages listed in requirements.txt.
-
Install Packages from .whl Files If you want to install the packages from the downloaded .whl files without an internet connection, you can use the following command:
pip install --no-index --find-links=packages/ -r requirements.txt
--find-links=packages/: Tells pip to look for the .whl files in the packages/ directory. 5. Restore Dependencies To restore the environment in the future, simply repeat the process of downloading the .whl files and installing them from the local files.
Additional Notes Make sure the Python version and system architecture are compatible with the .whl files you're downloading.
You can distribute the packages/ folder along with your requirements.txt to ensure that all dependencies are available for offline installations.
By following these steps, you'll be able to back up your Python packages as .whl files and install them later without needing an internet connection.