Using Packer, I am trying to create a Windows AMI with Python + the cryptography module installed. Here is the installation command I'm using for Python:
Invoke-Expression "python-3.6.8-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0"
Standalone that works fine. If I launch an EC2 instance from the resulting AMI, I can open Powershell and execute python --version
and it returns the Python version. This is to be expected since, according to Python documentation, PrependPath=1
will "Add install and Scripts directories to PATH"
In addition, however, I want to install cryptography module so I add the following to the install script:
Invoke-Expression "python-3.6.8-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0"
pip install --upgrade pip
pip install cryptography
Now Packer will fail when it gets to the pip command saying The term 'pip' is not recognized as the name of a amazon-ebs.windows: cmdlet, function, script file, or operable program.
I tried adding pip's location to the system path in multiple different ways but nothing helped. What did work (as well as the addition to the system path) was adding a sleep after the Python install command. Seemingly Packer/Powershell doesn't wait for the Python installer to finish. So now my install script looks like this:
Invoke-Expression "python-3.6.8-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0"
sleep 30
$env:Path += ";C:\Program Files\Python36\Scripts\"
pip install --upgrade pip
pip install cryptography
Now Packer executes no problem and creates the new AMI but when I launch the resulting AMI and run python --version
I get 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Adding commands to the script to append the system path has not helped.
Can anyone shed any light on this predicament?