Installation and Prerequisites
Prerequisites
Before installing Udility, ensure your environment meets the following requirements:
- Python Version: Python 3.6 or higher.
- OpenRouter API Key: This library requires an API key from OpenRouter to access the Meta Llama 3.5 models.
- System Libraries: Since Udility uses
cairosvgto render illustrations, you must have the Cairo graphics library installed on your operating system.
Installing Cairo (System-level)
If you encounter errors related to cairocffi or missing shared libraries, install Cairo using your system's package manager:
- macOS:
brew install cairo - Linux (Ubuntu/Debian):
sudo apt-get install libcairo2 - Windows: Follow the CairoSVG Windows installation guide (often involves downloading the GTK+ runtime).
Installation
Install the Udility package directly from PyPI using pip:
pip install Udility
Dependencies
The following Python libraries are automatically managed and installed during the setup process:
openai: For interfacing with OpenRouter.cairosvg: For converting SVG scripts into PNG images.matplotlib: For displaying the generated illustrations.Pillow: For image processing.
Configuration
Udility requires an environment variable to authenticate with the OpenRouter API. You can configure this in two ways:
Method 1: Environment Variable (Recommended)
Set the variable in your terminal session or add it to your .bashrc or .zshrc file:
export OPENROUTER_API_KEY='your_api_key_here'
Method 2: Python Script
Alternatively, you can set the environment variable directly within your Python script before importing the diffuser module:
import os
# Define the key before using Udility
os.environ['OPENROUTER_API_KEY'] = 'your_api_key_here'
from Udility import diffuser
Verification
To verify that the installation was successful and the environment is correctly configured, run the following snippet:
from Udility import diffuser
try:
# This will attempt to connect to the API and generate a simple test image
diffuser.generate_image_from_text("A simple circle.")
print("Installation successful!")
except Exception as e:
print(f"Installation check failed: {e}")