test/ensure_requests.py

26 lines
847 B
Python

import subprocess
import sys
import os
print(f"Python executable: {sys.executable}")
print(f"Current working directory: {os.getcwd()}")
try:
import requests
print(f"Requests is already installed: {requests.__version__}")
except ImportError:
print("Requests is NOT installed. Attempting installation...")
try:
# Use full path to pip in the same venv
pip_path = os.path.join(os.path.dirname(sys.executable), 'pip')
print(f"Using pip at: {pip_path}")
result = subprocess.run([pip_path, "install", "requests"], capture_output=True, text=True)
print("STDOUT:", result.stdout)
print("STDERR:", result.stderr)
import requests
print(f"Successfully installed requests: {requests.__version__}")
except Exception as e:
print(f"Installation failed: {e}")