DEV Community

Mario García
Mario García

Posted on

Hygeia: Managing Python toolchains with Rust

If you're a python dev, you may be familiar with the use of pyenv for managing the interpreters available on your system.

pyenv is written in Bash, that's why it only works on Linux or macOS. For Windows users there's a fork named pyenv-win.

Hygeia, a Python interpreter manager, built with Rust, works similar to pyenv, but aims to be portable across Windows, Linux and macOS.

Note: If you're using a tool like Poetry or pipenv for managing the dependencies of your project, install it before Hygeia.

Installation

The Requirements section in the README.md file in the repository contains instructions for installing dependencies of Hygeia on macOS and Linux. On Windows, just download the latest version from the release page.

If you're using Linux, check pyenv's wiki, as dependencies are the same.

After installing dependencies, download and extract Hygeia installer. Run the following commands in the Linux terminal:

$ curl -s https://api.github.com/repos/nbigaouette/hygeia/releases/latest \
  | grep "browser_download_url.*linux" \
  | cut -d : -f 2,3 \
  | tr -d \" \
  | wget -qi - -O hygeia.zip

$ unzip hygeia.zip
Enter fullscreen mode Exit fullscreen mode

Where1:

  • Use curl to get the JSON response for the latest release
  • Use grep to find the line containing file URL
  • Use cut and tr to extract the URL
  • Use wget to download it

Once you download and extract Hygeia, run:

$ ./hygeia setup <SHELL>
Enter fullscreen mode Exit fullscreen mode

Replacing <SHELL> with bash, zsh or powershell.

Hygeia is set up and ready to use it. Now you can remove the files downloaded.

$ rm hygeia*
Enter fullscreen mode Exit fullscreen mode

Basic Commands

To see the commands available, just type hygeia --help.

$ hygeia --help

hygeia v0.3.7 (712c5f2a5 2021-03-27)
Control which Python toolchain to use on a directory basis

USAGE:
    hygeia [FLAGS] [SUBCOMMAND]

FLAGS:
    -h, --help       
            Prints help information

    -V, --version    
            Prints version information

    -v, --verbose    
            Verbose mode (-v, -vv, -vvv, etc.)


SUBCOMMANDS:
    help       Prints this message or the help of the given subcommand(s)
    install    Install version, either from the provided version or from '.python-version'
    list       List installed Python versions
    path       Get path to active interpreter
    run        Run a binary from the installed '.python-version'
    select     Select specified Python versions to use
    setup      Setup the shim
    update     Update pycors to latest version
    version    Get version of active interpreter
Enter fullscreen mode Exit fullscreen mode

hygeia list will display the interpreters available on your system.

$ hygeia list

+--------+---------+---------------------+---------------------------------------------------+
| Active | Version | Installed by hygeia | Location                                          |
+--------+---------+---------------------+---------------------------------------------------+
|        |  3.9.2  |                     | /usr/bin                                          |
+--------+---------+---------------------+---------------------------------------------------+
|        |  3.7.6  |          ✓          | /home/user/.hygeia/installed/cpython/3.7.6/bin    |
+--------+---------+---------------------+---------------------------------------------------+
Enter fullscreen mode Exit fullscreen mode

For checking the Python version being used in the current directory, run:

$ hygeia version

3.9.2
Enter fullscreen mode Exit fullscreen mode

For installing any version of Python, run:

$ hygeia install =3.7.6
Enter fullscreen mode Exit fullscreen mode

This command will download and install Python 3.7.6. It will create a new directory into $HOME/.hygeia/installed/cpython, named 3.7.6. Any Python interpreter installed using hygeia is built with --enable-shared.

To set the active Python interpreter, type hygeia select =3.7.6 in the directory of your project.

To uninstall a specific Python toolchain, just remove the directory from $HOME/.hygeia/installed/cpython.

Poetry support

Create a new project with Poetry:

$ poetry new project_name
Enter fullscreen mode Exit fullscreen mode

Change to the project directory:

$ cd project_name
Enter fullscreen mode Exit fullscreen mode

Install and set the Python interpreter:

$ hygeia install =3.7.6
$ hygeia select =3.7.6
Enter fullscreen mode Exit fullscreen mode

Tell Poetry what version of Python to use:

$ poetry env use $HOME/.hygeia/installed/cpython/3.7.6/bin/python
Enter fullscreen mode Exit fullscreen mode

If you're using Hygeia along with Poetry, you must specify the full path where the Python binary is stored.

Install dependencies of your project:

$ poetry install
Enter fullscreen mode Exit fullscreen mode

Your environment is ready and you can start writing code.

Top comments (0)