Jump to content

Recommended Posts

Posted

Hi.

 

I'm currently trying to find a way to mass deploy a fix for getting pip to work on some of the computers here via a Group Policy Object. Our systems are currently using Windows 10.

 

There is already a software install for Python 3.9.5 on our Group Policy system, however it doesn't seem to be installing pip and it hasn't updated the PATH either.

 

The current fix I've found works, but it is long-winded and will take ages to complete as it's running the following steps one computer at a time:

1) Make sure Python 3.9.5 and Pygame for 3.9 Groups have been assigned to the computer you want it on via Active Directory.

Then restart those computers and check that Python and Pygame is installing upon turning on again. If it isn't installing,

then login to admin account and run "gpupdate /force" and restart those computers again.

 

Once Python 3.9.5 has appeared in the Start Menu of that computer, you will know it has installed.

 

2) Login to an admin account and run CMD as an admin. Type in "pip3 --version". If it returns a location where it is, then

it is working properly and you can skip to Step 5. If it says it is not a recognisable command, then you will need to

proceed into doing the following.

 

3) Open up Control Panel and search for "path" in the search box. Click on "Edit environment variables for your account".

You should see a variable called "Path" under the User Variables. Click it and then click "Edit". If you don't see

two lines with python in the path name, then you will need to add them. Click "New" and type in the following:

C:\Program Files\Python39\

Press Enter to confirm it, now press "New" again, this time typing in:

C:\Program Files\Python39\Scripts

Press Enter to confirm it, now press "OK" twice to save changes.

 

Restart your CMD window as Admin and try running the "pip3 --version" command again. If it works, skip to step 5.

Otherwise continue with Step 4.

 

4) In the elevated CMD window, type in the following command: "py -m ensurepip --upgrade". This should install pip.

Now restart your CMD window again as Admin and test the "pip3 --version" command, it should work now.

 

5) You are now ready to install any python packages via the 'pip3' command. Use these to install pygame and guizero:

pip3 install pygame

pip3 install guizero

I'm hoping there's a reliable way I can apply the above steps into some kind of start-up script and create it as a GPO to apply alongside the Python install GPO so it can successfully install on all machines in one go.

 

If someone can point me in the right direction or provide a set of instructions to follow, that would be much appreciated.

Posted

We're currently installing it through .msi files on the server through Group Policy Management. The policy then gets linked to a security group on Active Directory and then assigned to the computers. Here's some screenshots of what we're looking at if that helps:

PythonMSI.PNGPythonGPO.PNGPythonGPO2.PNG

Posted

I’d just dump the msi method for python and use a BAT/PS script (unless you have something like SCCM to do exe packages?)

 

Then you can use the standard install switches for python

 

pythoninstaller.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 Include_pip=1

 

Etc

 

Steve

Posted
I’d just dump the msi method for python and use a BAT/PS script (unless you have something like SCCM to do exe packages?)

 

Then you can use the standard install switches for python

 

pythoninstaller.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 Include_pip=1

 

Etc

 

Steve

Agreed.

 

We install Python and modules via a Startup batch file. Old school, but works well.

Posted

We managed to get it working via running command line tasks to groups of computers in the ESET console.

 

Turned out that this version of Python (3.9.5) that we had uses "py" commands.

 

I first checked the computer which had Python installed on it, if it had pip by checking this folder: ‘C:\Program Files\Python39\Lib\site-packages’.

I noticed there was no such folder with pip in its name here.

I then went to our ESET console to run the following command to all of our computers on the network which needed python on them (I'm sure a similar network management software has the ability to do this too): py -m pip install

 

After rechecking the folder, pip had now been successfully deployed on those computers.

I could then create a separate task to run for things like pygame and guizero by running these via ESET too:

-py -m pip install guizero

-py -m pip install pygame

 

If in the future I'm to install a later version of Python etc, I will for sure do it via some kind of package manager, batch script or powershell command etc instead.

Posted
"py command comes with Python3.x and allows you to choose among multiple Python interpreters. For example, if you have both Python 3.4 and 2.7 installed, py -2 will start python2.7, and py -3 will start python3.4. If you just use py it will start the one that was defined as default."
  • Thanks 1
  • 6 months later...
Posted
Agreed.

 

We install Python and modules via a Startup batch file. Old school, but works well.

 

Don't suppose you could share your script could you? Thanks!

Posted
Don't suppose you could share your script could you? Thanks!

It's a two reboot install. The first boot installs Python, and a second reboot installs Modules. I've tried installing Modules after installing Python, but couldn't get it to work.

 

If you want to add another Module at a later date, just add it to the end of the list and modify the script to check if it exists.

 

Hope this helps.

 

@echo off
REM Checks for Python v3.8 and installs
REM Checks for last module and installs modules on next reboot after Python install

If not exist "C:\Program Files\Python38\python.exe" (
 goto:INSTALL_PYTHON
) else (
 goto:CHECK_LAST_MODULE
)

:INSTALL_PYTHON
START /WAIT \\svr-01\Packages\Installers\Python3.8\python-3.8.0-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Shortcuts=1
goto:END


:CHECK_LAST_MODULE
REM Checks if last module installed
cd "C:\Program Files\Python38\Scripts"
if not exist "C:\Program Files\Python38\Scripts\thonny.exe" (
 goto:INSTALL_MODULES
) else (
 goto:end
)

:INSTALL_MODULES
  python -m pip install --upgrade pip
  pip3 install --upgrade Pillow
  pip3 install --upgrade Matplotlib
  pip3 install --upgrade pygame
  pip3 install --upgrade tk
  pip3 install --upgrade pandas
  pip3 install --upgrade requests
  pip install thonny
  
:END

  • Thanks 3
  • 8 months later...
Posted (edited)

I think I've finally achieved the holy grail of installing Python + Thonny + additional packages in a single hit using your script as the basis.

It's a two reboot install. The first boot installs Python, and a second reboot installs Modules. I've tried installing Modules after installing Python, but couldn't get it to work.

The reason it needs the second run of the script is that the install updates the PATH variable to point to the python and pip binaries. The cmd prompt instance that is running the installer batch doesn't get this updated version of the path variable while it's still running, removing the

goto: end

after the installation of Python and adding the following code will read the updated path variables from the registry and re-set them in the current instance just before it runs pip so it now knows where to look for it.

 

REM Get system path from registry
for /f "tokens=3*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path') do set syspath=%%A %%B
REM Get user path from registry
for /f "tokens=3*" %%A in ('reg query "HKCU\Environment" /v Path') do set userpath=%%A %%B
REM Set updated pathset PATH=%userpath%;%syspath%

Edited by JamieJ
  • Thanks 1
Posted
I think I've finally achieved the holy grail of installing Python + Thonny + additional packages in a single hit using your script as the basis.

 

Excellent, that's very helpful. I'll update my script accordingly. Cheers.

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