优化sys.path逻辑

This commit is contained in:
puke
2025-11-09 20:46:32 +08:00
parent 1f89e643a5
commit a195ac2deb
2 changed files with 20 additions and 1 deletions

View File

@@ -22,6 +22,16 @@ Or with custom settings:
uv run python api/app.py --host 0.0.0.0 --port 8080 --reload uv run python api/app.py --host 0.0.0.0 --port 8080 --reload
""" """
import sys
from pathlib import Path
# Add project root to sys.path for module imports
# This ensures imports work correctly in both development and packaged environments
_script_dir = Path(__file__).resolve().parent
_project_root = _script_dir.parent
if str(_project_root) not in sys.path:
sys.path.insert(0, str(_project_root))
import argparse import argparse
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from fastapi import FastAPI from fastapi import FastAPI

View File

@@ -16,10 +16,19 @@ Pixelle-Video Web UI
A simple web interface for generating short videos from content. A simple web interface for generating short videos from content.
""" """
import sys
from pathlib import Path
# Add project root to sys.path for module imports
# This ensures imports work correctly in both development and packaged environments
_script_dir = Path(__file__).resolve().parent
_project_root = _script_dir.parent
if str(_project_root) not in sys.path:
sys.path.insert(0, str(_project_root))
import asyncio import asyncio
import base64 import base64
import os import os
from pathlib import Path
import streamlit as st import streamlit as st
from loguru import logger from loguru import logger