4

I'm trying to package up our code base for deployment. The package will also need to include all the dependency packages in requirements.txt. In the past what I did was setup a virtualenv for the project and package up the code base along with the virtualenv site-packages. I'm wondering if there's an easier way for me just to grab all the dependency in the requirements.txt and just package those along with theirs dependencies and my code base.

Thanks.


Thank you for all the comments and suggestions, I think I found what I'm looking for. I ended creating a temporary folder (pip install --target ./temp) where my script parses the requirements.txt and installs all the modules in there to the temporary folder. This gives me the isolation of all the modules and their dependencies that I needed.

Ali Atiia
  • 139
  • 7
noobius
  • 1,529
  • 7
  • 14
  • Looks like others had the same question you did; it seems there's a few useful programs to do just that. Maybe this will help? [List dependencies in Python](https://stackoverflow.com/questions/42237072/list-dependencies-in-python) – Nick Reed Dec 17 '19 at 15:26
  • 3
    What does "package up" mean exactly? Create a ZIP file? Or a Python wheel? – deceze Dec 17 '19 at 15:27
  • @deceze, zip package – noobius Dec 17 '19 at 15:31
  • 2
    Do you have a specific tool that's supposed to do that, or are you doing that manually? While it's sometimes necessary to package programs as ZIP including dependencies, it's unusual. Packaging only the program itself and including a *list* of dependencies which can then be fetched as needed is more common. When you do need a ZIP file (AWS Lambda and such comes to mind), there are often specialised tools for that which will take care of the packaging. Some context would help here. – deceze Dec 17 '19 at 15:33
  • @deceze, yeah I'm creating package for aws lambda, I used some tool such as serverless. However for this, I can't use some of the tools that our organization haven't approve yet, so I'm stuck with packaging up myself. Currently I'm thinking of a simple python script to execute using zipfile, but I need a way to get a hold of all the dependencies. – noobius Dec 17 '19 at 15:44

1 Answers1

1

It's super simple, go into your virtualenv and do pip freeze -l > requirements.txt. That will populate your requirements properly. At the other end the only thing you need to do to have all the right package is pip install -r requirements.txt.

Yacine Mahdid
  • 723
  • 5
  • 17