Created
September 20, 2023 18:07
-
-
Save dataserver/10ecfa38368b2ae19c59bd46707139a1 to your computer and use it in GitHub Desktop.
powershell script to activate python venv and running a script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Demo script to activate Python VENV and running a script | |
.DESCRIPTION | |
Demo script to activate Python VENV and running a script with some args capture by the powershell | |
.EXAMPLE | |
scriptname.ps1 -name blabla | |
#> | |
param ( | |
[Parameter(Mandatory=$false)][string]$name | |
) | |
# Configure the path to your virtual environment | |
$venvPath = "D:\path\to\python\.venv" | |
# Configure the path to the parent folder where app.py is located | |
$appPath = "D:\path\to\python\app" | |
if (!$name) { | |
Write-Host "Name not defined" -ForegroundColor Red | |
exit 1 | |
} | |
Write-Host "Activating the virtual environment..." | |
Set-Location -Path "$venvPath" | |
.\Scripts\Activate.ps1 | |
if ( $env:VIRTUAL_ENV ) { | |
Write-Host "Success" -ForegroundColor Green | |
} else { | |
Write-Host "Failed" -ForegroundColor Red | |
exit 1 | |
} | |
Write-Host "Running script..." | |
python "$appPath\main.py" -name $name | |
deactivate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment