Spaces:
Paused
Paused
| import os | |
| import subprocess | |
| import sys | |
| import venv | |
| from pathlib import Path | |
| def setup_project(): | |
| # Ensure we're in the right directory | |
| project_dir = Path(__file__).parent.absolute() | |
| os.chdir(project_dir) | |
| print("Setting up the project...") | |
| # Create virtual environment if it doesn't exist | |
| venv_dir = project_dir / "myenv" | |
| if not venv_dir.exists(): | |
| print("Creating virtual environment...") | |
| venv.create(venv_dir, with_pip=True) | |
| # Determine the path to the Python executable in the virtual environment | |
| if sys.platform == "win32": | |
| python_executable = venv_dir / "Scripts" / "python.exe" | |
| pip_executable = venv_dir / "Scripts" / "pip.exe" | |
| else: | |
| python_executable = venv_dir / "bin" / "python" | |
| pip_executable = venv_dir / "bin" / "pip" | |
| # Upgrade pip | |
| print("Upgrading pip...") | |
| subprocess.run([str(python_executable), "-m", "pip", "install", "--upgrade", "pip"]) | |
| # Install requirements | |
| print("Installing requirements...") | |
| requirements_file = project_dir / "requirements.txt" | |
| if requirements_file.exists(): | |
| subprocess.run([str(pip_executable), "install", "-r", "requirements.txt"]) | |
| else: | |
| print("Warning: requirements.txt not found!") | |
| print("\nSetup completed successfully!") | |
| print("\nTo activate the virtual environment:") | |
| if sys.platform == "win32": | |
| print(f" {venv_dir}\\Scripts\\activate") | |
| else: | |
| print(f" source {venv_dir}/bin/activate") | |
| if __name__ == "__main__": | |
| setup_project() |