Jump to content

Recommended Posts

Posted

Good Afternoon,

 

I've been asked to look into installing Python and Pygame on our network. Has anyone recently got both installed successfully? I'm having a bit of an issue installing Python via GPO so any help would be greatly appreciated!

Posted

Do you have some way to Bulk run commands?

 

\\NetPath\Python\python-xxxx.exe /quiet InstallAllUsers=1 PrependPath=1 TargetDir="C:\Program Files\PythonXXX" Include_pip=1

 

Should install it

Then something like this for PyGame

 

"C:\Program Files\Python313\python.exe -m pip install pygame --upgrade pip --proxy http://Proxy:8080"

 

you can package all of this in a logon PowerShell script, but would need some more finesse

Posted (edited)

Installing Python, and pygame using PowerShell works well, I am using a signed PowerShell script.

Here is my PowerShell code

 

# Script to install Python v3.13.1

# Using Powershell to use UNC

 

## Test if Python v3.13.1 already installed, and exit if installed

if (Test-Path "C:\Program Files\python\python3.13.1") {

exit

}

 

## If Python folder doe not exist, then create it

If (-not (test-path "C:\Program Files\Python")) {

New-Item -ItemType "directory" -Path "C:\Program Files" -name "Python"

}

 

## Install Python 3.13.0

cd \\joa-app01\Repository\Python\Python\

Start-Process -filepath ".\python-3.13.1-amd64.exe" -ArgumentList "/passive", "/InstallAllUsers" -Wait

 

## Install marker to show Python version

New-Item -itemType File -path "C:\Program Files\Python" -Name "Python3.13.1"

 

## Remove old marker, if exists

If (Test-Path "C:\Program Files\python\python3.13.0"){

Remove-Item "C:\Program Files\python\python3.13.0"

}

 

## Explicitly set no proxy

$Env:http_proxy =""

$Env:https_proxy =""

 

## Install / Update Python libraries

CD "C:\Program Files\Python\Scripts"

.\pip.exe install wheel --no-warn-script-location

.\pip.exe install Pygame --no-warn-script-location

.\pip.exe install numpy --no-warn-script-location

.\pip.exe install pyopengl --no-warn-script-location

 

# SIG # Begin signature block

# Signing code goes here

 

 

Note

I am using “Start-Process” so that the install of Python competes, before starting the install of the library components.

(PowerShell will do line sequentially, except when there is a Windows command, then they will be done simultaneously)

 

Ihope that this is of some help.

Edited by Julian
Posted

Similar to Julian, I use a powershell script that checks the current version and updates based on the latest installer in the directory. Once python is installed, the path variable is updated, then pip is updated and the specified modules installed.

 

$Modules = @(
   'matplotlib',
   'pygame',
   'sounddevice',
   'scipy',
   'wavio'
)

$Exes = Get-ChildItem "\\example.org\Applications\Python\" -Filter "*.exe"

$Arguments = "InstallAllUsers=1 PrependPath=1 /quiet"

[Version]$HighestVersion = 0.0.0.0
Foreach ($Exe in $Exes) {
   [Version]$ExeVersion = $Exe.VersionInfo.FileVersion
   If ($HighestVersion -lt $ExeVersion) {
       $HighestVersion = $ExeVersion
       $Highest = $Exe
   }
   $InstallPath = $Highest.FullName
}

$CurrentVersions = @()
$Currents = (Get-Package -ProviderName Programs -IncludeWindowsInstaller -Name "*Python*" -ErrorAction SilentlyContinue) | Where-Object {$_.Name -notlike "*Launcher*"}
Foreach ($Current in $Currents) {
   $CurrentVersions += @($Current.Version)
}

Foreach ($CurrentVersion in $CurrentVersions) {
   If ($CurrentVersion -lt $HighestVersion) {
       $Uninstaller = $Exes | Where-Object {$_.VersionInfo.FileVersion -eq $CurrentVersion}
       $UninstallPath = $Uninstaller.FullName

       Start-Process -FilePath $UninstallPath -ArgumentList "/uninstall /quiet" -NoNewWindow -Wait
   }
}

$CurrentVersions = @()
$Currents = (Get-Package -ProviderName Programs -IncludeWindowsInstaller -Name "*Python*" -ErrorAction SilentlyContinue) | Where-Object {$_.Name -notlike "*Launcher*"}
Foreach ($Current in $Currents) {
   $CurrentVersions += @($Current.Version)
}

If ($Currents -eq $Null) {
   $Installed = $False
}
Else {
   $Installed = $True
}
    
If (!($Installed)) {
   Start-Process -FilePath $InstallPath -ArgumentList $Arguments -NoNewWindow -Wait

   Sleep -Seconds 5
   $env:Path = [system.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [system.Environment]::GetEnvironmentVariable("Path","User")
}

Start-Process -FilePath "Python" -ArgumentList "-m pip install --upgrade pip" -NoNewWindow -Wait
$InstallModules = ""
Foreach ($Module in $Modules) {
   $InstallModules += " $Module"
}

Start-Process -FilePath "python" -ArgumentList "-m pip install $InstallModules" -NoNewWindow -Wait

Posted
Depending on your ISP and web filter, I found we had to add a https decrypt exclusion for the pipi site as it got stuck on there being a self-signed cert for the filter.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...