I installed and tested poetry for the past couple of days, it works much better at a repo/project level (building the environment is much faster than conda). The initializer for a project is very nice and if they can incorporate the data science cookie cutter template with git initialization that would be a super handy feature.
The only thing keeping it from fully replacing miniforge for me is that it doesn’t include a python distribution (so if you install 3.9 on the system but your teammate needs 3.11, it won’t build a new venv with 3.11) and the instructions to install on windows are not super beginner friendly.
My ideal workflow is having conda manage the python versions (as it creates a completely new python directory), and install poetry to each python version environment (3.10, 3.11, 3.12). As I work on projects, I make local repo venvs which make the process of sharing environments with collaborators easier. Also with local venvs, vs code is able to pick it up when selecting the interpreter and will actually default to the venv rather than the conda environments.
A potential use case for poetry is when working company laptops that restrict admin access and only allows python to be installed from a company app store/portal, as you can install python and then point poetry to the python version from the windows path
installation woes
The curl python method for whatever reason used an older version of python on my system, and no amount of environment variables wrangling allowed me to point poetry to use a different distribution.
The suggested pipx method on windows also didn’t work either, so instead I used pip to install pipx
If you are also on windows and use miniconda/miniforge, these steps below worked for me
I did some further exploration of this ideal case while setting it up on my fedora desktop, I found that you don’t necessarily need to use pipx (which will isolate poetry from the base environment).
The original instructions are still valid, these new instructions are for those who want conda as the python version manager and poetry as the package manager. Using a pyproject.toml in conjunction with a local venv is very handy as the workflow for installing packages using poetry add, is very intentional and logs packages you need.
In an ideal python development environment, you would create a new conda environment for each project. In practice, I’ve found that I neglect my conda environments because switching between environments and projects is too cumbersome. Conda environments will duplicate the full python installation, whereas .venvs will just include the custom packages that get installed on top of an existing python install. Furthermore, using vs code/codium, loading the python kernel for jupyter notebooks using local .venvs is much faster than waiting for the conda environment
I wanted to use conda environments for each python version I use
install miniforge, miniconda or anaconda
if you are in a corporate environment and your org doesn’t have a anaconda license, make sure to use miniforge or use the set your default channel to conda-forge
activate your newly created conda environment, again replace $env_name with the name you gave to your environment
conda activate $env_name
install poetry with pip
python -m pip install poetry
note: python -m ensures that you will use the pip local to your environment, you shouldn’t need it by default, but I have it that way to avoid using the system’s global pip
install poetry-conda to have poetry install to your local repo
note: as of the current moment, if poetry is installed to an conda environment, it will default to the venv directory within the conda environment. There have been numerous proposals for how to resolve this. Ranging from variable flags, to documentation revisions, and even a poetry-conda plugin as seen below
Yeah it’s definitely a tool you want in your toolbox if you want to keep track of your project’s dependencies or if you want to build python packages.
I found that poetry will append new packages to the end of the dependencies section, so it’s easier to track as I work on a project.
side tangent expanding the note in step 5
I just wish that poetry had a way to manage python versions better (the documentation recommends having poetry isolated, but doing so with conda really screws with the local project level venv.
There’s been an ongoing discussion of how poetry should dump .venvs within conda environments
Hopefully they can implement the proposals suggested in the thread