Python Packages Offline Installation

I have some virtual machines for testing, but these machines are offline and cannot connect to the Internet. I was having trouble installing the Python module. I can use whl file to install the package, but the package dependencies cannot be installed. This has bothered me for a long time, and now I can finally install the package and its dependencies offline. The following is offline installation method.

Backup

First, install all packages and dependencies on the local machine (which has internet). Then back up all the packages and dependencies.

#  Confirm the installed package 
c:\tmp>pip list  
#  Generate requirements.txt 
c:\tmp>pip freeze > requirements.txt    
#  Create a new folder 
c:\tmp>mkdir packs  
#  Backup 
c:\tmp>pip download -d C:/tmp/packs -r requirements.txt  

Installation

Copy the requirements.txt and packs folder to offline machine.

# Install backed up packages and dependencies
c:\tmp>pip install --no-index --find-links=C:\tmp\packs\ -r requirements.txt
# Confirm the installed list
c:\tmp>pip list

References

https://stackoverflow.com/questions/11091623/python-packages-offline-installation/51646354
https://www.cnblogs.com/michael-xiang/p/5690746.html
https://www.jianshu.com/p/10e8fe694e03

Leave a Reply

Your email address will not be published.