Installing Python Libraries on a School Network

This question keeps coming up on various forums and on Twitter so I thought I would share how we install Python and the extra libraries we use across our school network. A recent discussion on Twitter between Chris Sharples and Laura caught my attention.

Chris was asking Laura for an MSI package version of her fantastic GUI Zero Python library.


So I offered to write up a blog post about how we install extra Python packages across our school network.


Now all school networks differ and, as they say, YMMV! But for what it’s worth here’s how we do it…

We use MDT to build and deploy our Windows client installations, but this method could quite easily be adapted for Active Directory Group Policy use, or even SCCM (but I haven’t used that so don’t ask me how!).

First off we grab the latest installer of Python 3 from over here: https://www.python.org/downloads/windows/ and then following the instructions here: https://docs.python.org/3/using/windows.html we build ourselves an installation wrapper script for adding the Python package to our MDT setup.

We want the install process to happen completely silently but also to include all of the extra parts of the standard Python installer we want. Our script for installing Python looks like this:

python-3.5.2.exe /quiet InstallAllUsers=1 PrependPath=1 Shortcuts=1

mkdir "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Academic\Computing\Python"
copy  "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Python 3.5\*.*" "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Academic\Computing\Python"
RD /Q/S "%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Python 3.5"

So that gets us Python installed silently for all users with Python added to our system PATH. If you look at the docs page linked to above you will see that the installer also installs PIP by default too. The last three lines of this script just tidy up our shortcuts.

But what about adding the extra Python Libraries I hear you ask!

Well we do that using PIP; now that our install script has taken care of installing Python we can just add a new line for each library we want to install using PIP. Now most schools will have their Internet behind a proxy filter but luckily PIP has the ability to download it’s packages through a proxy: https://pip.pypa.io/en/stable/reference/pip/#cmdoption-proxy

There was one more thing we had to do, as our proxy is an authenticating proxy server but I did not want to hard-code a user name and password into our install wrapper scripts. So to get PIP to be able to just download it’s packages straight through the proxy server, we added python.org into a control group on our proxy server which allows access to that domain through unauthenticated. – See comment at the bottom of the page!

So now we can add a few lines to the end of our installation wrapper script like this:

pip install pillow --proxy <Proxy IP>:<Proxy Port>
pip install matplotlib --proxy <Proxy IP>:<Proxy Port>
pip install guizero --proxy <Proxy IP>:<Proxy Port>

Now when we set up a new machine or re-image an existing one, all of our required Python libraries are available from the word go!

1 thought on “Installing Python Libraries on a School Network

  1. With changes to how the Raspberry Pi handles Python packages, I have since had to add two more domains to my whitelisted / non-auth’ed websites to get this to work:
    1. piwheels.org
    2. pypi.org

Leave a Reply to Jon Witts Cancel reply

Your email address will not be published. Required fields are marked *