Install new library

Installing New Libraries in Your Float16 Remote Instance

This tutorial will guide you through adding new libraries to your Float16 remote instance. Since the remote instance starts as an empty container, you need to install libraries before running your code.

This example scenario, we'll use a script 'cat.py' that imports the 'requests' library to fetch data from a cat fact API.

import requests

cat_fact = requests.get('https://catfact.ninja/fact')
if cat_fact.status_code == 200:
    print("\nFun fact about cats:")
    print(cat_fact.json()['fact'])

While you can simply use pip install requests on your local machine, the process is different for the remote instance.

Step 1 : Create requirements.txt

Create a requirements.txt file to specify dependencies.

float16 init

This command creates both 'float16.conf' and 'requirements.txt' files.

Open 'requirements.txt' and add the following

requests==2.31.0

This specifies the library name and the version you want to install.

Step 2 : Start the Project

Start the container, which automatically installs packages listed in 'requirements.txt'

float16 project start

Step 3 : Update Libraries (if needed)

After starting the project and successfully installing packages, you might find that the installed version doesn't match your local version. This could potentially affect your code. Here's how to update

Check the current version: pip show <PACKAGE> | grep Version or pip list

To upgrade the version (e.g., from '2.31.0' to '2.32.3'), edit 'requirements.txt'

requests==2.32.3

Update package dependencies

float16 project install

Step 4 : Run Your Script

Execute your script

float16 run cat.py

Example output (The response is randomly generated, so you may see a different cat fact.):

Fun fact about cats:
The average lifespan of an outdoor-only cat is about 3 to 5 years while an indoor-only cat can live 16 years or much longer.

Congratulations! You've become proficient in installing new libraries in your Float16 remote instance.

Explore More

Learn how to use Float16 CLI for various use cases in our tutorials.

Happy coding with Float16 Serverless GPU!

Last updated