Installing Python Packages Without Internet Access
Download Python packages on a connected machine, transfer them, and install them in an environment without internet access.
To install Python packages on a machine without internet access, download the packages and their dependencies on another machine, then transfer them to the offline environment. The process has three steps.
Download Packages in an Online Environment
First, use pip download in an environment with internet access to download the required Python packages.
pip install boto3pip freeze > requirements.txtpip download --dest packages -r requirements.txtThis saves the packages and their dependencies in the packages directory.
Transfer the Packages to the Offline Environment
Create an archive containing the downloaded packages and transfer it to the target environment with a secure tool such as scp.
tar cvzf packages.gz ./packages# Transfer the archive to the offline environmentInstall Packages in the Offline Environment
Extract the archive in the offline environment, then run pip install with the --find-links and --no-index options.
tar xvzf packages.gzpip install -r requirements.txt --find-links packages --no-indexThe --find-links option points to the local directory containing the packages, and --no-index ensures pip does not try to access the PyPI index.
Conclusion
Download the required distributions with pip download, transfer the packages directory, and install from it with --find-links and --no-index. The offline machine does not need network access during installation.
The --find-links option tells pip to search the local packages directory, while --no-index prevents it from querying PyPI.
By default, pip download resolves distributions for the machine on which it runs. If the online and offline environments differ, specify --platform, --python-version, and --implementation together with --only-binary=:all: to download wheels compatible with the offline target.
Related posts
Monitoring OPC UA Variable Nodes with Python
Subscribing to OPC UA variable node changes with opcua-asyncio so the client reacts to pushed updates instead of polling.
Performing OCR on Japanese PDFs Using Tesseract and Pytesseract
Extracting Japanese text from a PDF with Tesseract OCR v4 and pytesseract, including the normalization step needed to clean up the output.
Running Proxy.py as a Lightweight HTTP Proxy on EC2
Running Proxy.py on an EC2 instance and reaching it safely through an SSH tunnel, since the proxy has no authentication of its own.
Dependency Injection for Maintainable, Testable Code
Refactor a tightly coupled TypeScript class by injecting its salary calculator, system clock, and Amazon SES mailer.
Spying on Mock Object Properties in Jasmine
Working around Jasmine's "already been spied upon" error when spying on a mocked object's property with Object.getOwnPropertyDescriptor.
