Skip to main content

Using packages

Working with packages is an important part of using Python in Hex.

Use a pre-installed package#

Hex has a number of popular packages pre-installed and immediately ready for import into your project. You can see the list of pre-installed packages in the Environment tab in the left-hand bar.

Default packages are listed in the Environment tab of the left side bar

Install new packages through pip#

You can add new packages to a project using pip, much as you would in a local environment.

Create a new cell, and use a ! to trigger a terminal command:

!pip3 install astropy

Because projects are run from top to bottom with a new kernel every time a user visits, packages installed with !pip install have to be reinstalled every time your project runs.

Fixed package versioning#

When starting a new kernel, Hex loads specific versions of pandas and pyarrow. This process causes these packages to remain fixed to the versions that Hex imports, meaning that these packages cannot be updated from within a Hex project.

GitHub packages#

If your workspace has been set up to use packages from a GitHub repository, you can install those packages for use in any project. See GitHub packages for setup instructions.

environment-configuration/use-github-package@2x

To import functions from .py files included in your package, you will first need to add the path to those files to your Python path. Packages are automatically saved to a directory with the naming convention of {{GitHub user}}-{{GitHub package name}}. For example, the screenshot above shows how to import functions from the draw_hexagon.py file of the draw_hexagon packages, which is associated with the izzymiller GitHub user.

Depending on how your GitHub package has been configured, some modules may have already been installed. In this case, those modules are immediately available for use, just import {{package name}} in a Python cell as usual.

GitHub packages are re-imported from GitHub with every kernel restart of your project. If your package is particularly large this can add some overhead to the intial performance and load time of your projects. Additionally, if your GitHub package was configured to import a specific branch of the package, upon each kernel restart, the latest version of the branch will be imported.