I don't have enough reputation to comment but an enhancement to @Liang's answer is to omit the echo and call poetry itself.
cat requirements.txt | grep -E '^[^# ]' | cut -d= -f1 | xargs -n 1 poetry add
In my case, this successfully added packages to the pyproject.toml
file.
For reference this is a snippet of my requirements.txt
file:
pytz==2020.1 # https://github.com/stub42/pytz
python-slugify==4.0.1 # https://github.com/un33k/python-slugify
Pillow==7.2.0 # https://github.com/python-pillow/Pillow
and when calling cat requirements.txt | grep -E '^[^# ]' | cut -d= -f1
(note the omission of xargs -n 1 poetry add
for demonstration) it will output the following:
pytz
python-slugify
Pillow
# NOTE: this will install the latest package - you may or may not want this.
Adding dev dependencies is as simple as adding the -D
or --dev
argument.
# dev dependancies example
cat requirements-dev.txt | grep -E '^[^# ]' | cut -d= -f1 | xargs -n 1 poetry add -D
Lastly, if your dev requirements install from a parent requirements file, for example:
-r base.txt
package1
package2
Then this will generate errors when poetry runs, however, it will continue past the -r base.txt
line and install the packages as expected.
Tested on Linux manjaro with poetry installed as instructed here.
pip freeze > requirements.txt
on command line? – Copularequirements.txt
file. I would like to import it into Poetry without having to type in the packages manually. – Infrequentpip freeze
. – Cliffordrequirements.txt
. You can use dephell, but I don't know how good or reliable that is. Honestly, I'd always do dependency porting by hand, since it's one of the parts of an app that can lead to serious problems and technical debt if it's not cared for as good as possible. – Clifford