Convert poetry.lock file into a requirements.txt and download the packages

Views: 13
0 0
Read Time:1 Minute, 42 Second

This guide will show you how to convert poetry.lock file into a requirements.txt and download the packages into a specific subfolder step by step.

Poetry vs pip

Poetry is starting to be more and more popular between developers as package manager for python projects (more information here https://python-poetry.org/docs/cli/) but one of the lacking thing I see is the ability to download only the libraries/packages like pip is doing with the -t flag. With this command we can download/install all the poetry.lock packages into a specific folder.

If your projects are managed with Poetry, and you want to download locally the packages into a particular subfolder for having a deeper look at the source code before using, maybe for curiosity or maybe because the company you are looking for is strongly regulated and there are particular policies in place, or maybe you just want to run and end to end static analysis and want to get more insight these are the commands that you were looking for.

Please note that at the moment of writing this article the poetry version in use is 1.1 and this functionality is still missing so this article could be invalid in a couple of months or years depends on how much is a priority for their team this functionality.

By looking around and reading here and there I found a combination of commands that will definitely be extremely useful.

Export poetry.lock into requirements.txt

To export your poetry.lock into requirements.txt just run the below command

poetry export -f requirements.txt -o requirements.txt --without-hashes

Download packages locally using pip

Once we have the requirements.txt file we can download into the destination we prefer (in our example will be the packages folder) by running this command

mkdir packages && pip install -r requirements.txt -t ./packages

I hope that helped and if you like it please share.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Previous post Get records from the database with Python and SQLAlchemy
Next post How to generate random numbers with python
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x