Jump to content

Recommended Posts

Posted

Hi everyone,

 

Long time listener, first time caller.

 

I want to manage Python packages centrally for our Computer Science students.

Previously, this was done via a little script that called pip, and pointed it at a requirements file stored on the network, and the script ran via scheduled task deployed by a GPO.

 

This worked great until it didn't.

 

I want to avoid local requirements files, and want them to be managed automagically and centrally. Maybe that's too much to ask.

 

I am still rewriting the script, but I am also interested to see if there's a better way that perhaps someone here has implemented?

 

 

Posted

I'm not sure if this helps, but we have this run as a PS Script as a "startup" script. 

If we want to add any packages / update we add it to the list here and update the check file name.

Pulls down 95% of the dependencies too

 

$CheckFile = Get-Item "c:\Pip314_1025.txt"
if (!(Get-Item $CheckFile)){
    $Date = Get-Date -Format dd_MM_yyyy_hh_mm
    $HostN = HOSTNAME
    new-item "c:\PythonLogs\" -ItemType Directory
    Start-Transcript "c:\PythonLogs\$HostN`_$Date.txt" #Logging
    $PythonPath = "C:\Program Files\Python314\python.exe"
    $ThonnyPath = "C:\Program Files\Python314\Lib\site-packages\thonny\config.py" ##Uses config as thers no thonny.exe
    if (Get-Item $PythonPath){
    $packages = "matplotlib" ,"thonny","numpy","easygui","pyparsing","tomli", "piglet","astroid","pillow","sphinx","pygame","twine","python-docx","pandas"
    & $PythonPath -m pip install --upgrade pip --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org
    Start-Sleep -Seconds 10
    foreach ($Package in $Packages){
    & $PythonPath -m pip install $Package --upgrade --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org
    }
    if (Get-Item $ThonnyPath){
        New-Item $CheckFile -Force
    }
    }
    else{
        Write-Host "Python Is Not Installed"
    }
    Stop-Transcript 
}

 

Posted

Cool! Thank you for sharing!

 

This line here:

 

$PythonPath = "C:\Program Files\Python314\python.exe"

 

..is similar to what prompted me to rewrite our script too. Once we updated Python the script no longer worked, an obvious oversight on my part looking back on it now.

Posted
12 minutes ago, technikerinunbekannt said:

Cool! Thank you for sharing!

 

This line here:

 

$PythonPath = "C:\Program Files\Python314\python.exe"

 

..is similar to what prompted me to rewrite our script too. Once we updated Python the script no longer worked, an obvious oversight on my part looking back on it now.

TBF "Python.exe" or whatever the correct syntax is when doing it that way should just work if python is installed and on PATH 

i did it this way so we could have multiple Python versions at once / test new versions 

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...