Windows Install Script Update
This commit is contained in:
@@ -33,21 +33,58 @@ if (-not $isAdmin) {
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
# Function to refresh environment PATH
|
||||
function Refresh-Path {
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
||||
# Also add common Chocolatey paths
|
||||
$chocoPath = "$env:ProgramData\chocolatey\bin"
|
||||
if (Test-Path $chocoPath) {
|
||||
$env:Path = "$chocoPath;$env:Path"
|
||||
}
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Step 1: Install Chocolatey (Package Manager)
|
||||
# -----------------------------------------------------------------------------
|
||||
Write-Host "[STEP 1/7] Checking Chocolatey..." -ForegroundColor Green
|
||||
|
||||
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "[INFO] Installing Chocolatey..." -ForegroundColor Yellow
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
||||
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
||||
$chocoInstalled = $false
|
||||
try {
|
||||
$chocoVersion = choco --version 2>$null
|
||||
if ($chocoVersion) {
|
||||
$chocoInstalled = $true
|
||||
Write-Host "[INFO] Chocolatey already installed (version $chocoVersion)" -ForegroundColor Green
|
||||
}
|
||||
} catch {
|
||||
$chocoInstalled = $false
|
||||
}
|
||||
|
||||
# Refresh environment
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
||||
} else {
|
||||
Write-Host "[INFO] Chocolatey already installed" -ForegroundColor Green
|
||||
if (-not $chocoInstalled) {
|
||||
Write-Host "[INFO] Installing Chocolatey..." -ForegroundColor Yellow
|
||||
|
||||
try {
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
|
||||
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
||||
|
||||
# Refresh environment to find choco
|
||||
Refresh-Path
|
||||
|
||||
# Verify installation
|
||||
$chocoPath = "$env:ProgramData\chocolatey\bin\choco.exe"
|
||||
if (Test-Path $chocoPath) {
|
||||
Write-Host "[INFO] Chocolatey installed successfully" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[ERROR] Chocolatey installation failed. Please install manually:" -ForegroundColor Red
|
||||
Write-Host " https://chocolatey.org/install" -ForegroundColor Yellow
|
||||
Write-Host "[INFO] After installing Chocolatey, close and reopen PowerShell, then run this script again." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
Write-Host "[ERROR] Failed to install Chocolatey: $_" -ForegroundColor Red
|
||||
Write-Host "[INFO] Please install Chocolatey manually: https://chocolatey.org/install" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -56,21 +93,81 @@ if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
|
||||
Write-Host ""
|
||||
Write-Host "[STEP 2/7] Installing Python..." -ForegroundColor Green
|
||||
|
||||
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
|
||||
choco install python311 -y
|
||||
# Refresh environment
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
||||
} else {
|
||||
Write-Host "[INFO] Python already installed" -ForegroundColor Green
|
||||
$pythonInstalled = $false
|
||||
try {
|
||||
$pythonVersion = python --version 2>$null
|
||||
if ($pythonVersion -match "Python 3") {
|
||||
$pythonInstalled = $true
|
||||
Write-Host "[INFO] Python already installed ($pythonVersion)" -ForegroundColor Green
|
||||
}
|
||||
} catch {
|
||||
$pythonInstalled = $false
|
||||
}
|
||||
|
||||
if (-not $pythonInstalled) {
|
||||
Write-Host "[INFO] Installing Python 3.11..." -ForegroundColor Yellow
|
||||
|
||||
# Use full path to choco if needed
|
||||
$chocoExe = "$env:ProgramData\chocolatey\bin\choco.exe"
|
||||
if (Test-Path $chocoExe) {
|
||||
& $chocoExe install python311 -y
|
||||
} else {
|
||||
choco install python311 -y
|
||||
}
|
||||
|
||||
Refresh-Path
|
||||
|
||||
# Verify
|
||||
try {
|
||||
$pythonVersion = python --version
|
||||
Write-Host "[INFO] Python installed ($pythonVersion)" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[ERROR] Python installation failed" -ForegroundColor Red
|
||||
Write-Host "[INFO] Please install Python 3.11 manually from https://python.org" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Step 3: Install Visual C++ Build Tools
|
||||
# Step 3: Install Visual C++ Build Tools (optional but recommended)
|
||||
# -----------------------------------------------------------------------------
|
||||
Write-Host ""
|
||||
Write-Host "[STEP 3/7] Installing Visual C++ Build Tools..." -ForegroundColor Green
|
||||
Write-Host "[STEP 3/7] Checking Visual C++ Build Tools..." -ForegroundColor Green
|
||||
|
||||
choco install visualstudio2022-workload-vctools -y
|
||||
# Check if cl.exe exists (Visual C++ compiler)
|
||||
$vsInstalled = $false
|
||||
$vsPaths = @(
|
||||
"C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC",
|
||||
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC",
|
||||
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC"
|
||||
)
|
||||
|
||||
foreach ($path in $vsPaths) {
|
||||
if (Test-Path $path) {
|
||||
$vsInstalled = $true
|
||||
Write-Host "[INFO] Visual C++ Build Tools found" -ForegroundColor Green
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $vsInstalled) {
|
||||
Write-Host "[INFO] Visual C++ Build Tools not found" -ForegroundColor Yellow
|
||||
Write-Host "[INFO] Attempting to install (this may take 10-20 minutes)..." -ForegroundColor Yellow
|
||||
|
||||
try {
|
||||
$chocoExe = "$env:ProgramData\chocolatey\bin\choco.exe"
|
||||
if (Test-Path $chocoExe) {
|
||||
& $chocoExe install visualstudio2022-workload-vctools -y
|
||||
} else {
|
||||
choco install visualstudio2022-workload-vctools -y
|
||||
}
|
||||
Write-Host "[INFO] Visual C++ Build Tools installed" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[WARN] Could not install Visual C++ Build Tools automatically" -ForegroundColor Yellow
|
||||
Write-Host "[INFO] PyBullet may fail to install. If it does, install Visual Studio Build Tools manually:" -ForegroundColor Yellow
|
||||
Write-Host " https://visualstudio.microsoft.com/visual-cpp-build-tools/" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Step 4: Download and Install ROS 2
|
||||
@@ -91,7 +188,15 @@ if (-not (Test-Path $ros2Path)) {
|
||||
$ros2Zip = "$env:TEMP\ros2-humble.zip"
|
||||
|
||||
Write-Host "[INFO] This may take a while (1-2 GB download)..." -ForegroundColor Yellow
|
||||
Invoke-WebRequest -Uri $ros2Url -OutFile $ros2Zip
|
||||
|
||||
try {
|
||||
# Use BITS for more reliable download
|
||||
Start-BitsTransfer -Source $ros2Url -Destination $ros2Zip -DisplayName "Downloading ROS 2"
|
||||
} catch {
|
||||
# Fallback to Invoke-WebRequest
|
||||
Write-Host "[INFO] Using alternative download method..." -ForegroundColor Yellow
|
||||
Invoke-WebRequest -Uri $ros2Url -OutFile $ros2Zip
|
||||
}
|
||||
|
||||
Write-Host "[INFO] Extracting ROS 2..." -ForegroundColor Yellow
|
||||
Expand-Archive -Path $ros2Zip -DestinationPath "C:\dev" -Force
|
||||
@@ -133,7 +238,7 @@ $requirementsFile = Join-Path $ProjectRoot "requirements.txt"
|
||||
if (Test-Path $requirementsFile) {
|
||||
pip install -r $requirementsFile
|
||||
} else {
|
||||
pip install pybullet pyinstaller
|
||||
pip install pybullet pyinstaller pillow
|
||||
}
|
||||
|
||||
Write-Host "[INFO] Python packages installed in venv" -ForegroundColor Green
|
||||
@@ -149,7 +254,7 @@ $activateBat = Join-Path $ProjectRoot "activate.bat"
|
||||
@"
|
||||
@echo off
|
||||
REM =============================================================================
|
||||
REM Drone Competition - Environment Activation Script (Windows CMD)
|
||||
REM Drone Simulation - Environment Activation Script (Windows CMD)
|
||||
REM =============================================================================
|
||||
REM Usage: activate.bat
|
||||
REM =============================================================================
|
||||
@@ -164,6 +269,7 @@ echo.
|
||||
echo [OK] Environment ready! You can now run:
|
||||
echo python simulation_host.py
|
||||
echo python ros_bridge.py
|
||||
echo python controllers.py
|
||||
echo.
|
||||
"@ | Out-File -FilePath $activateBat -Encoding ASCII
|
||||
|
||||
@@ -171,7 +277,7 @@ echo.
|
||||
$activatePs1 = Join-Path $ProjectRoot "activate.ps1"
|
||||
@"
|
||||
# =============================================================================
|
||||
# Drone Competition - Environment Activation Script (Windows PowerShell)
|
||||
# Drone Simulation - Environment Activation Script (Windows PowerShell)
|
||||
# =============================================================================
|
||||
# Usage: . .\activate.ps1
|
||||
# =============================================================================
|
||||
@@ -188,6 +294,7 @@ Write-Host ""
|
||||
Write-Host "[OK] Environment ready! You can now run:" -ForegroundColor Green
|
||||
Write-Host " python simulation_host.py"
|
||||
Write-Host " python ros_bridge.py"
|
||||
Write-Host " python controllers.py"
|
||||
Write-Host ""
|
||||
"@ | Out-File -FilePath $activatePs1 -Encoding UTF8
|
||||
|
||||
@@ -218,6 +325,12 @@ try {
|
||||
Write-Host " PyInstaller: FAILED" -ForegroundColor Red
|
||||
}
|
||||
|
||||
try {
|
||||
python -c "import PIL; print(' Pillow: OK')"
|
||||
} catch {
|
||||
Write-Host " Pillow: FAILED" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "==============================================" -ForegroundColor Cyan
|
||||
Write-Host " IMPORTANT: Activate the environment first!" -ForegroundColor Cyan
|
||||
@@ -229,4 +342,6 @@ Write-Host " PowerShell: . $activatePs1" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "Then run the simulation:" -ForegroundColor Yellow
|
||||
Write-Host " python simulation_host.py" -ForegroundColor White
|
||||
Write-Host " python ros_bridge.py" -ForegroundColor White
|
||||
Write-Host " python controllers.py" -ForegroundColor White
|
||||
Write-Host ""
|
||||
|
||||
Reference in New Issue
Block a user