How Can I Add Python Packages to the Leap IDE?

The Leap IDE comes pre-loaded with a wide variety of useful Python packages that you can use right away with your code. To see what packages are automatically installed, open the IDE terminal and type "pip list" or "pip freeze".

Sometimes, you may need to use some more specialized packages that aren't preloaded. These can usually be installed using "pip install <package-name>" in the IDE terminal.

Preloaded packages are installed globally; packages that you add are installed using "pip user scheme" with "PYTHONUSERBASE" pointing to /workspace/.pip-modules. Bear in mind that only user site packages are persisted across workspace restarts.

If you want to set up a repository for others to use, you can ensure that they have the right packages installed by using a requirements file, which is usually named "requirements.txt". A requirements file lists the packages and, optionally, the version numbers that you used to run your code. The requirements file can be created easily from your local environment by typing "pip freeze > requirements.txt".

In the IDE, you can list (or save) only the user-installed packages by adding the "--user" option to either "pip list" or "pip freeze".

When a repository has a requirements.txt file, you can open the Leap IDE and install all the Python packages at once by typing "pip install -r requirements.txt" in the terminal.

An alternative method that starts up any new workspace from your repository with these requirements.txt packages preloaded is to use a .gitpod.yml file. Create a new file in your repository named ".gitpod.yml" and include only the following two lines in that file:

- init: pip install -r requirements.txt

Now, when a new workspace is started from this repository, the new additional packages are automatically installed from your requirements file. Note that when the IDE opens your new workspace, it may take a few extra seconds to finish installing the new packages. When you open a Python file and the packages are ready to be used, the green run button in the top right is enabled.

To check that your additional packages have been installed in the Leap IDE (with either the "pip install" or .yml file method), type "pip freeze --user" in the terminal to see the additional packages with version numbers or "pip freeze" to see all packages that are installed both globally and for user site.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.