# Guía de Instalación - Nexus Autoparts ## Requisitos del Sistema ### Software Requerido | Software | Versión Mínima | Propósito | |----------|----------------|-----------| | Python | 3.8+ | Lenguaje principal | | pip | 20.0+ | Gestor de paquetes | | Git | 2.0+ | Control de versiones | ### Sistema Operativo El proyecto es compatible con: - Linux (Ubuntu, Debian, CentOS, etc.) - macOS - Windows 10/11 ### Espacio en Disco - Mínimo: 50 MB - Recomendado: 100 MB (para crecimiento de la base de datos) --- ## Instalación Rápida ```bash # 1. Clonar el repositorio git clone https://git.consultoria-as.com/[usuario]/Nexus-Autoparts.git # 2. Entrar al directorio cd Nexus-Autoparts # 3. Instalar dependencias pip install -r requirements.txt # 4. Iniciar el dashboard cd dashboard python3 server.py ``` --- ## Instalación Detallada ### Paso 1: Clonar el Repositorio ```bash git clone https://git.consultoria-as.com/[usuario]/Nexus-Autoparts.git cd Nexus-Autoparts ``` ### Paso 2: Crear Entorno Virtual (Recomendado) ```bash # Crear entorno virtual python3 -m venv venv # Activar entorno virtual # Linux/macOS: source venv/bin/activate # Windows: venv\Scripts\activate ``` ### Paso 3: Instalar Dependencias ```bash # Instalar todas las dependencias pip install flask requests beautifulsoup4 lxml # O usando requirements.txt pip install -r requirements.txt ``` ### Paso 4: Verificar la Base de Datos La base de datos viene pre-poblada con datos. Para verificar: ```bash cd vehicle_database sqlite3 vehicle_database.db "SELECT COUNT(*) FROM brands;" ``` ### Paso 5: Inicializar (Opcional) Si necesitas reiniciar la base de datos: ```bash cd vehicle_database ./setup.sh ``` --- ## Dependencias de Python ### Archivo requirements.txt ``` flask==2.3.3 requests>=2.28.0 beautifulsoup4>=4.11.0 lxml>=4.9.0 ``` ### Instalación Individual ```bash # Flask - Framework web pip install flask # Requests - Cliente HTTP pip install requests # BeautifulSoup4 - Parser HTML pip install beautifulsoup4 # lxml - Parser XML/HTML rápido pip install lxml ``` --- ## Configuración ### Variables de Entorno (Opcional) ```bash # Puerto del servidor (default: 5000) export FLASK_PORT=5000 # Modo debug (solo desarrollo) export FLASK_DEBUG=1 # Ruta de la base de datos export DATABASE_PATH=/path/to/vehicle_database.db ``` ### Configuración del Servidor Editar `dashboard/server.py`: ```python # Cambiar puerto app.run(host='0.0.0.0', port=5000, debug=False) # Para producción app.run(host='0.0.0.0', port=8080, debug=False) ``` --- ## Verificación de la Instalación ### 1. Verificar Python ```bash python3 --version # Debería mostrar: Python 3.8.x o superior ``` ### 2. Verificar Dependencias ```bash python3 -c "import flask; print(f'Flask: {flask.__version__}')" python3 -c "import requests; print(f'Requests: {requests.__version__}')" python3 -c "import bs4; print(f'BeautifulSoup: {bs4.__version__}')" ``` ### 3. Verificar Base de Datos ```bash cd vehicle_database python3 -c " import sqlite3 conn = sqlite3.connect('vehicle_database.db') cursor = conn.execute('SELECT COUNT(*) FROM brands') print(f'Marcas en BD: {cursor.fetchone()[0]}') conn.close() " ``` ### 4. Probar el Dashboard ```bash cd dashboard python3 server.py & curl http://localhost:5000/api/brands ``` --- ## Solución de Problemas ### Error: ModuleNotFoundError ```bash # Verificar que el entorno virtual está activado which python3 # Reinstalar dependencias pip install --force-reinstall flask requests beautifulsoup4 lxml ``` ### Error: Database is locked ```bash # Cerrar todas las conexiones a la base de datos # Reiniciar el servidor pkill -f server.py python3 dashboard/server.py ``` ### Error: Port already in use ```bash # Encontrar proceso usando el puerto lsof -i :5000 # Matar el proceso kill -9 [PID] # O usar otro puerto python3 server.py --port 5001 ``` ### Error: Permission denied ```bash # Dar permisos de ejecución a scripts chmod +x vehicle_database/setup.sh chmod +x dashboard/start_dashboard.sh chmod +x QUICK_START.sh ``` --- ## Instalación en Producción ### Usando Gunicorn (Recomendado) ```bash # Instalar Gunicorn pip install gunicorn # Iniciar servidor cd dashboard gunicorn -w 4 -b 0.0.0.0:8080 server:app ``` ### Usando systemd Crear archivo `/etc/systemd/system/nexus-autoparts.service`: ```ini [Unit] Description=Nexus Autoparts Dashboard After=network.target [Service] User=www-data WorkingDirectory=/path/to/Nexus-Autoparts/dashboard ExecStart=/usr/bin/python3 server.py Restart=always [Install] WantedBy=multi-user.target ``` Habilitar e iniciar: ```bash sudo systemctl enable nexus-autoparts sudo systemctl start nexus-autoparts ``` ### Usando Docker (Opcional) ```dockerfile FROM python:3.11-slim WORKDIR /app COPY . /app RUN pip install flask requests beautifulsoup4 lxml EXPOSE 5000 CMD ["python3", "dashboard/server.py"] ``` ```bash docker build -t nexus-autoparts . docker run -p 5000:5000 nexus-autoparts ``` --- ## Actualizaciones ```bash # Obtener últimos cambios git pull origin main # Actualizar dependencias pip install --upgrade -r requirements.txt ``` --- ## Desinstalación ```bash # Desactivar entorno virtual deactivate # Eliminar directorio del proyecto rm -rf Nexus-Autoparts # Eliminar entorno virtual (si está separado) rm -rf venv ```