Python environments provide sandboxes in which packages can be added. Conda helps us deal with the requirements and dependencies of those packages. Occasionally we find ourselves working in a constrained remote machine which can make development challenging. Suppose we wanted to take our exact dev environment on the remote machine and recreate it on our local machine. While conda relieves the package dependency challenge, it can be hard to reproduce the exact same environment.

Creating a Portable Python Environment

This walkthrough will demonstrate a method to copy an exact environment on one machine and transfer it to a another machine. We’ll start by collecting the package requirements of a given set of python files, create an environment based on those requirements, then export it as a tarball for distribution on a target machine.

Setup

Sample files

For this walkthrough we’ll assume you have a folder with some python files as a rudimentary “package”.

If you want to create some example files, run the following commands:

mkdir -p ./test_package echo "import scipy" >> ./test_package/first_file.py echo "import numpy" >> ./test_package/first_file.py

echo "import pandas" >> ./test_package/second_file.py echo "import sklearn" >> ./test_package/second_file.py

Each file has a few import statements - nothing fancy.

#conda #conda-pack #depfinder #python

Creating a Portable Python Environment from Imports
1.50 GEEK