0

I have two VMs one is development VM and one is Production VM. Development VM has internet access but production VM dont have it and will not get access.

I want some python packages to be installed to run some script. In development VM I installed those packages. Script is running file. I want to migrate this packages to production VM. Where pip is not installed as well as internet is also not there.

I am looking for a way i can zip the packages migrate it to prod VM using scp and install over there.

I can not directly zip python2.7/site-packages where packages are being installed by pip because there are many unnecessary packages present in development VM. I want only those which are required for script to run with all its dependency.

I tried downloading source tar.gz from https://pypi.org/ and install it through "setup.py install" but it requires so much dependency issues.

I am looking for solution like i create directory all the packages will be installed in that directories with all the dependencies. And i can zip it and put it in other setup.

Also a way so that it doesnt upgrade any of the packages preinstalled.

phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    https://stackoverflow.com/a/14447068/7976758 Found in https://stackoverflow.com/search?q=%5Bpip%5D+offline – phd Mar 30 '23 at 14:11

1 Answers1

1

Build a "wheelhouse" on the machine that has internet connection. Something like the following, check pip's documentation for exact command and details.

First, in the environment you want to mirror, get the list of dependencies:

python -m pip freeze > requirements.txt

Maybe, edit the requirements.txt file to remove dependencies that you do not want or need. It might be more or less complex to figure out what dependencies should be kept in the requirements.txt file or not. You can use tools like deptree, pipdeptree, creosote, pipreqs, or pigar.

Then build the actual wheelhouse, you might want to do this in a fresh empty virtual environment, if you are worried about making modifications in your source environment:

python -m pip wheel --requirement requirements.txt --wheel-dir=wheelhouse/

The wheelhouse directory can be copied over to the target machine.

And the dependencies can be installed in the target environment with pip without internet connection:

python -m pip install --no-index wheelhouse/*.whl

If the target machine, really does not have pip (which seems quite unlikely), you could use a zipapp-based solution such as pex or shiv.

sinoroc
  • 18,409
  • 2
  • 39
  • 70