Technical requirements
As explained in the Preface, you’ll need to set up your Python environment and install and import the Polars library. Here’s how to install the Polars library using pip
:
>>> pip install polars
If you want to install all the optional dependencies, you’ll need to use the following:
>>> pip install 'polars[all]'
If you want to install specific optional dependencies, you’ll use the following:
>>> pip install 'polars[pyarrow, pandas]'
Here’s a line of code to import the Python Polars library:
import polars as pl
You can find the code and dataset from this chapter along with datasets used in the GitHub repository here: https://github.com/PacktPublishing/Polars-Cookbook.
In addition to Polars, you will need to install the Graphviz library, which is required to visually inspect the query plan:
>>> pip install graphviz
You will also need to install the Graphviz package on your machine. Please refer to this website for how to install the package on your chosen OS: https://graphviz.org/download/.
I installed it on my Mac using Homebrew with the following command:
>>> brew install graphviz
For Windows users, the simplified steps are as follows:
- Select whether you want to install the 32-bit or the 64-bit version of Graphviz.
- Visit the download location at https://gitlab.com/graphviz/graphviz/-/releases.
- Download the 32-bit or 64-bit exe file:
- The 32-bit
.exe
file: https://gitlab.com/graphviz/graphviz/-/package_files/6164165/download - The 64-bit
.exe
file: https://gitlab.com/graphviz/graphviz/-/package_files/6164164/download
- The 32-bit
Please refer to these instructions for a more detailed explanation of how to install Graphviz on Windows: https://forum.graphviz.org/t/new-simplified-installation-procedure-on-windows/224.
You can find more information about Graphviz in general here: https://graphviz.readthedocs.io/en/stable/.