remove venv from web v2

This commit is contained in:
Chuck
2025-08-11 11:27:03 -05:00
parent 151777fbd6
commit 28c81825cc
6 changed files with 95 additions and 135 deletions

View File

@@ -22,39 +22,8 @@ logging.basicConfig(
logger = logging.getLogger(__name__)
def setup_virtual_environment():
"""Set up a virtual environment for the web interface."""
venv_path = Path(__file__).parent / 'venv_web_v2'
if not venv_path.exists():
logger.info("Creating virtual environment...")
try:
subprocess.check_call([
sys.executable, '-m', 'venv', str(venv_path)
])
logger.info("Virtual environment created successfully")
except subprocess.CalledProcessError as e:
logger.error(f"Failed to create virtual environment: {e}")
return None
return venv_path
def get_venv_python(venv_path):
"""Get the Python executable path from the virtual environment."""
if os.name == 'nt': # Windows
return venv_path / 'Scripts' / 'python.exe'
else: # Unix/Linux
return venv_path / 'bin' / 'python'
def get_venv_pip(venv_path):
"""Get the pip executable path from the virtual environment."""
if os.name == 'nt': # Windows
return venv_path / 'Scripts' / 'pip.exe'
else: # Unix/Linux
return venv_path / 'bin' / 'pip'
def check_dependencies(venv_path):
"""Check if required dependencies are installed in the virtual environment."""
def check_dependencies():
"""Check if required dependencies are installed."""
required_packages = [
'flask',
'flask_socketio',
@@ -64,25 +33,19 @@ def check_dependencies(venv_path):
'freetype'
]
# Use the virtual environment's Python to check imports
venv_python = get_venv_python(venv_path)
missing_packages = []
for package in required_packages:
try:
subprocess.check_call([
str(venv_python), '-c', f'import {package}'
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError:
__import__(package)
except ImportError:
missing_packages.append(package)
if missing_packages:
logger.warning(f"Missing packages: {missing_packages}")
logger.info("Installing missing packages in virtual environment...")
logger.info("Installing missing packages...")
try:
venv_pip = get_venv_pip(venv_path)
subprocess.check_call([
str(venv_pip), 'install', '-r', 'requirements_web_v2.txt'
sys.executable, '-m', 'pip', 'install', '-r', 'requirements_web_v2.txt'
])
logger.info("Dependencies installed successfully")
except subprocess.CalledProcessError as e:
@@ -92,10 +55,9 @@ def check_dependencies(venv_path):
# Install rgbmatrix module from local source
logger.info("Installing rgbmatrix module...")
try:
venv_pip = get_venv_pip(venv_path)
rgbmatrix_path = Path(__file__).parent / 'rpi-rgb-led-matrix-master' / 'bindings' / 'python'
subprocess.check_call([
str(venv_pip), 'install', '-e', str(rgbmatrix_path)
sys.executable, '-m', 'pip', 'install', '-e', str(rgbmatrix_path)
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
logger.info("rgbmatrix module installed successfully")
except subprocess.CalledProcessError as e:
@@ -125,29 +87,22 @@ def main():
script_dir = Path(__file__).parent
os.chdir(script_dir)
# Set up virtual environment
venv_path = setup_virtual_environment()
if not venv_path:
logger.error("Failed to set up virtual environment. Exiting.")
sys.exit(1)
# Check dependencies in virtual environment
if not check_dependencies(venv_path):
# Check dependencies
if not check_dependencies():
logger.error("Dependency check failed. Exiting.")
sys.exit(1)
# Check permissions
check_permissions()
# Import and start the web interface using the virtual environment's Python
# Import and start the web interface using system Python
try:
venv_python = get_venv_python(venv_path)
logger.info("Web interface loaded successfully")
# Start the server using the virtual environment's Python
# Start the server using system Python
logger.info("Starting web server on http://0.0.0.0:5001")
subprocess.run([
str(venv_python), 'web_interface_v2.py'
sys.executable, 'web_interface_v2.py'
])
except Exception as e: