Python Poetry – dependency manager plus packaging tool
I was hearing about this awesome new kid on the block called Poetry. I had taken a look on it in the past (approx two years ago) and it looked not as finished as pipenv, so had stuck with pipenv + setup.py. But over the weekend, I decided to take another look at it after hearing that Poetry 1.0 has been released. And it looked really promising. Looks like I can finally say goodbye to my pipenv+setup.py based workflow which I was never comfortable with.
Install:
Caution: Even though the library is in 1.0 .. meaning build stable, there are some cautions one needs to take. The official install instructions will make a mess if you have multiple Python versions in your computer, in particular.. Python2.7 as default.
Firstly, the official documentation is here: https://python-poetry.org/docs/
But you need to keep a few things in mind before you install.
- DON’T install it inside your existing virtual environment, or a virtual environment you plan to use for your project. Reason: poetry is a python project with dependencies and your project is also a python project with dependencies. If you put them both in the same virtual environment, there are bound to be clashes.
- install poetry like so:
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3.7
Notice that I explicitly specified python3.7. If it was just python, poetry would have installed with python2.7, which is horrible since Python2.7 is officially retired. I use Python3.7. Hence this version. - After installing, you will need to source your ~/.profile file to make sure that poetry path is exported to your shell.
source ~/.profile
- Now, when your run
poetry --version
, you will get a warning like:
$ poetry --version /home/my_home/.poetry/lib/poetry/_vendor/py2.7/subprocess32.py:149: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads. "program uses threads.", RuntimeWarning) Poetry version 1.0.5
See the py2.7, it still referring to default Python on my system, which is Python2.7.
To finally get rid of this warning, and a BIG oversight by poetry team (IMHO), is to edit this file~/.poetry/bin/poetry
.
The very first line, sets up the python interpreter as /usr/bin/python which is Python2.7 for many linux distros, including mine. Change this to #!/usr/bin/env python3.7
That’s it, poetry is installed. You can go ahead and dopoetry --version
in your shell and all should be fine now. Happy coding!!