Mario García
Posted on April 8, 2021
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
Where1:
- Use
curl
to get the JSON response for the latest release - Use
grep
to find the line containing file URL - Use
cut
andtr
to extract the URL - Use
wget
to download it
Once you download and extract Hygeia, run:
$ ./hygeia setup <SHELL>
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*
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
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 |
+--------+---------+---------------------+---------------------------------------------------+
For checking the Python version being used in the current directory, run:
$ hygeia version
3.9.2
For installing any version of Python, run:
$ hygeia install =3.7.6
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
Change to the project directory:
$ cd project_name
Install and set the Python interpreter:
$ hygeia install =3.7.6
$ hygeia select =3.7.6
Tell Poetry what version of Python to use:
$ poetry env use $HOME/.hygeia/installed/cpython/3.7.6/bin/python
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
Your environment is ready and you can start writing code.
Posted on April 8, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.