Python 前言
- Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。
- Python 由 Guido van Rossum 于 1989 年底发明,第一个公开发行版发行于 1991 年。
- 像 Perl 语言一样, Python 源代码同样遵循 GPL(GNU General Public License) 协议。
Python download
Python | download |
pip | download |
Python 编程语言的软件存储库 | download |
Python 使用使用参数 | 参考 |
前提条件
- 开启wmi,配置网卡,参考
创建一键安装Python,pip自动化脚本
- 实现在线下载Python二进制包,pip,安装,环境变量,删除,企业微信机器人通知。
- Expand-Archive #解压文件
- Start-Process # 安装,等待安装完成在执行下一个
- Rename-Item #重命名文件夹参考
- "C:\python" #python安装位置
- Python 自动安装相关参数
- 更改脚本段信息$webhook = #企业微信机器人地址,用法参考
powershell-install-python-binary.ps1
<# Powershell Install python binary
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ _____ _____ _ _ _ +
+ | __ \ / ____| | | | |+
+ | |__) |____ _____ _ _| (___ | |__ ___| | |+
+ | ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | | | (_) \ V V / __/ | ____) | | | | __/ | |+
+ |_| \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++
# Powershell Install python binary
# .\powershell-install-python-binary.ps1
#>
$drive="c:"
$python_temporary="python_temporary"
$python="python"
$python_zip="python-3.10.1-embed-amd64.zip"
$pip_py="get-pip.py"
$pip_Scripts="Scripts"
Write-Host "Create a directory for storing python temporary" -ForegroundColor Green
New-Item -ItemType Directory $drive\$python_temporary
$python_related_download = @(
"https://www.python.org/ftp/python/3.10.1/python-3.10.1-embed-amd64.zip",
"https://bootstrap.pypa.io/get-pip.py"
)
foreach ($url in $python_related_download) {
$fileName = Split-Path $url -Leaf
$filePath = Join-Path $drive\$python_temporary $fileName
Invoke-WebRequest -Uri $url -OutFile $filePath
}
Write-Host "Unzip the python package" -ForegroundColor Green
Expand-Archive -Path $drive\$python_temporary\$python_zip -DestinationPath $drive\$python
Write-Host "Create python environment variables" -ForegroundColor Green
$env:path += ";$drive\$python"
$env:path += ";$drive\$python\$pip_Scripts"
setx PATH $env:path /M
Write-Host "install python pip" -ForegroundColor Green
python.exe $drive\$python_temporary\$pip_py
Write-Host "Copy the pip directory to the python directory" -ForegroundColor Green
Copy-Item -Path "$drive\$python\Lib\site-packages\pip" -Destination $drive\$python -Recurse
Write-Host "Delete related python installation packages and temporary directories" -ForegroundColor Green
Remove-Item -Path "$drive\$python_temporary\*.whl", "$drive\$python_temporary\*.zip", "$drive\$python_temporary" -Recurse -Force
#Enterprise wechat robot address
$webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXX"
#Obtain the Windows host system version
$Win_version = Get-WmiObject -Class Win32_OperatingSystem | Select-Object -ExpandProperty Caption
$Win_version_Names = echo $Win_version
#python version
$python_version = (Get-Item "$drive\$python\python.exe").VersionInfo.FileVersion
#pip version
$pip_version = pip.exe --version
$content = Write-Output ""Win_version: $Win_version_Names" `n "pip_version: $pip_version" `n "python_version: $python_version""
$body = "{
`"msgtype`":`"text`",
`"text`":{
`"content`":`"$content`",
`"mentioned_list`":[`"jason`"]
}
}"
Write-Host "The variable value obtained is transferred to the enterprise wechat robot" -ForegroundColor Green
Invoke-RestMethod $webhook -ContentType "application/json;charset=utf-8" -Method Post -Body $body
执行安装
.\powershell-install-python-binary.ps1
输出结果展示