Implement a command line shell by using Command Dispatcher in Python
Lets implement a command shell by using a command dispatcher. The objective is…
March 03, 2021
We will see how we can install Python 3.7 on Windows without UI. i.e. from command line
First we will run powershell. And run following commands on powershell console.
$url = ('https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe'); \
Write-Host ('Downloading {0} ...' -f $url); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri $url -OutFile 'python.exe'; \
\
Write-Host 'Installing ...'; \
Start-Process python.exe -Wait \
-ArgumentList @( \
'/quiet', \
'InstallAllUsers=1', \
'TargetDir=C:\Python37', \
'PrependPath=1', \
'Shortcuts=0', \
'Include_doc=0', \
'Include_pip=0', \
'Include_test=0' \
); \
\
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', [EnvironmentVariableTarget]::Machine); \
\
Write-Host 'Verifying install ...'; \
Write-Host ' python --version'; python --version; \
\
Write-Host 'Removing ...'; \
Remove-Item python.exe -Force; \
\
Write-Host 'Complete.'
ENV PYTHON_GET_PIP_SHA256 421ac1d44c0cf9730a088e337867d974b91bdce4ea2636099275071878cc189e
RUN Write-Host ('Downloading get-pip.py...'); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri "https://github.com/pypa/get-pip/raw/d59197a3c169cef378a22428a3fa99d33e080a5d/get-pip.py" -OutFile 'get-pip.py'; \
Write-Host ('Verifying sha256 ...'); \
if ((Get-FileHash 'get-pip.py' -Algorithm sha256).Hash -ne "421ac1d44c0cf9730a088e337867d974b91bdce4ea2636099275071878cc189e") { \
Write-Host 'FAILED!'; \
exit 1; \
}; \
\
Write-Host ('Installing pip ...'); \
python get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
; \
Remove-Item get-pip.py -Force; \
\
Write-Host 'Verifying pip install ...'; \
pip --version; \
\
Write-Host 'Complete.'
FROM microsoft/windowsservercore:ltsc2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN New-Item C:/temp -ItemType Directory; \
New-Item C:/data -ItemType Directory;
WORKDIR C:/temp
ENV PYTHON_VERSION 3.7.9
ENV PYTHON_RELEASE 3.7.9
RUN $url = ('https://www.python.org/ftp/python/{0}/python-{1}-amd64.exe' -f $env:PYTHON_RELEASE, $env:PYTHON_VERSION); \
Write-Host ('Downloading {0} ...' -f $url); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri $url -OutFile 'python.exe'; \
\
Write-Host 'Installing ...'; \
# https://docs.python.org/3.7/using/windows.html#installing-without-ui
Start-Process python.exe -Wait \
-ArgumentList @( \
'/quiet', \
'InstallAllUsers=1', \
'TargetDir=C:\Python37', \
'PrependPath=1', \
'Shortcuts=0', \
'Include_doc=0', \
'Include_pip=0', \
'Include_test=0' \
); \
\
#the installer updated PATH, so we should refresh our local value
$env:PATH = [Environment]::GetEnvironmentVariable('PATH', [EnvironmentVariableTarget]::Machine); \
\
Write-Host 'Verifying install ...'; \
Write-Host ' python --version'; python --version; \
\
Write-Host 'Removing ...'; \
Remove-Item python.exe -Force; \
\
Write-Host 'Complete.'
# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/d59197a3c169cef378a22428a3fa99d33e080a5d/get-pip.py
ENV PYTHON_GET_PIP_SHA256 421ac1d44c0cf9730a088e337867d974b91bdce4ea2636099275071878cc189e
RUN Write-Host ('Downloading get-pip.py ({0}) ...' -f $env:PYTHON_GET_PIP_URL); \
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
Invoke-WebRequest -Uri $env:PYTHON_GET_PIP_URL -OutFile 'get-pip.py'; \
Write-Host ('Verifying sha256 ({0}) ...' -f $env:PYTHON_GET_PIP_SHA256); \
if ((Get-FileHash 'get-pip.py' -Algorithm sha256).Hash -ne $env:PYTHON_GET_PIP_SHA256) { \
Write-Host 'FAILED!'; \
exit 1; \
}; \
\
Write-Host ('Installing pip ...'); \
python get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
; \
Remove-Item get-pip.py -Force; \
\
Write-Host 'Verifying pip install ...'; \
pip --version; \
\
Write-Host 'Complete.'
Hope you enjoy reading this post.
Lets implement a command shell by using a command dispatcher. The objective is…
Introduction You are having a form having multiple fields. When you render a…
Introduction You have a view with 4-5 fields to display. Suppose, there are two…
Introduction In this post, we will explore some useful command line options for…
Introduction In Azure, assuming you are having a storage container. And, you…
You have drupal 7 image from docker hub, and want to connect tomongo db via php…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…