Databytes

Daily bytes of learning

21 Mar 2023

Local Env Refresh | Poetry

Poetry Setup

Part of Local Python Environment Refresh Series

Today, I’m going to attempt using Poetry on a new project. The project will be simple TensorFlow MLP which is trained using randomly generated data. My plan is also to incorporate a new dependency called Hydra. I want to be able to run my model from the command line with various configurations of the both the data and model.

Here’s what I’m looking to accomplish right now:

  • Local isolated python environment dedicated to this project
  • Research Poetry and answer some of my questions

Questions about Poetry:

  • As I understand it, Poetry does not manage various versions of Python, how do I manage python versions? Do I use pyenv?
  • How does adding dependcies work?

Instillation

Starting on Poetry docs. Docs as of today, mention that you need >= Python 3.7. Going to research how to install poetry into an virtual environment, so I can manage different versions of Python.

I also noticed the docs references pipx for installing global Python CLI into isolated virtual environments. Seems interesting - adding to my investigate further list.

PyEnv

To manage various versions of Python, I’m going to use Pyenv. This package has been referred to me by colleagues, and from glancing at pipenv, the documentation mentions references pyenv.

The benefits from pyenv’s documentation also seem great:

What pyenv does…

  • Lets you change the global Python version on a per-user basis.
  • Provides support for per-project Python versions.
  • Allows you to override the Python version with an environment variable.
  • Searches for commands from multiple versions of Python at a time. This may be helpful to test across Python versions with tox.

Going to try instillation with Homebrew per recommendation.

Hiccup

My homebrew install was definitely broken! I got a couple weird errors. Did some research; this SO article was helpful.

brew doctor: Told me what was wrong with my install: “Broken symlinks were found” brew cleanup: The command the doctor suggested

Back to Pyenv brew install pyenv worked like a charm, but it took several minutes to download all the dependencies.

Will continue tomorrow with setting up my bash environment per the Pyenv directions.

Investigate Further

  • pipx