Skip to content

Python AI Installation and Configuration

Installation on Ubuntu 24.04

Verify Python version

Must be 3.12.*

python3 --version

Install Supervisor

apt update -y
apt install supervisor -y
systemctl status supervisor

Deploying from DeployHQ

Create a server deployment from the Method Grid app repository to the python server.

Follow DeployHQ's instructions for giving DeployHQ access to the server, then set the following options: - Deployment path: /usr/src/ai - Environment: production - Subdirectory to deploy from: ai/

Deploy the code.

Install dependencies

Create virtual environment and install dependencies:

apt-get update && apt-get install -y python3.12-venv

python3 -m venv /usr/src/ai/.venv
/usr/src/ai/.venv/bin/pip install --upgrade pip
/usr/src/ai/.venv/bin/pip install /usr/src/ai

Create .env file

Copy example .env file:

cp /usr/src/ai/src/mg_ai/.env.example /usr/src/ai/src/mg_ai/.env

Edit .env file with correct values.

Configuration

Create Python AI Supervisor .conf File

Create /etc/supervisor/conf.d/ai-websocket.conf:

[program:ai-websocket]
command=/usr/src/ai/.venv/bin/python /usr/src/ai/src/mg_ai/main.py
autostart=true
autorestart=true
stderr_logfile=/var/log/ai.error.log
stdout_logfile=/var/log/ai.log

Restart Supervisor

systemctl restart supervisor && systemctl enable supervisor

Verify that AI websocket server is running

supervisorctl status

Create Firewall Rules

The AI Python server firewall must allow incoming connections to ports 8000 from all web servers.

Webserver Proxy

This is handled by the apache config on the webservers and is covered by the instructions there. The key point is that the apache virtual host must include the following:

ProxyPass "/ai/ws" "ws://PYTHON_SERVER_IP:8000/socket.io"
ProxyPassReverse "/ai/ws" "ws://PYTHON_SERVER_IP:8000/socket.io"
Last modified by: Unknown