
Python 前言
- Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。
- Python 由 Guido van Rossum 于 1989 年底发明,第一个公开发行版发行于 1991 年。
- 像 Perl 语言一样, Python 源代码同样遵循 GPL(GNU General Public License) 协议。
Python download
Python | download |
pip | download |
Python 使用使用参数 | 参考 |
前提条件
创建一键安装Python,pip自动化脚本
- 实现在线下载Python ,pip,安装,环境变量,删除,企业微信机器人通知。
- Expand-Archive #解压文件
- Start-Process # 安装,等待安装完成在执行下一个
- Rename-Item #重命名文件夹参考
- "C:\python" #python安装位置
- Python 自动安装相关参数
- 更改脚本段信息$webhook = #企业微信机器人地址,用法参考
powershell-install-python.ps1
<# Powershell Install python
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+ _____ _____ _ _ _ +
+ | __ \ / ____| | | | |+
+ | |__) |____ _____ _ _| (___ | |__ ___| | |+
+ | ___/ _ \ \ /\ / / _ \ '__\___ \| '_ \ / _ \ | |+
+ | | | (_) \ V V / __/ | ____) | | | | __/ | |+
+ |_| \___/ \_/\_/ \___|_| |_____/|_| |_|\___|_|_|+
+ +++++++++++++++++++++++++++++++++++++++++++++++++++# Powershell Install python
# .\powershell-install-python.ps1
#>$drive="c:\"
$python_url="https://www.python.org/ftp/python/3.11.2/"
$python_exe="python-3.11.2-amd64.exe"
$python_site="C:\Program Files\"
$pytnon_new="python"$pip_url="https://bootstrap.pypa.io/"
$pip_py="get-pip.py"Write-Host "create Python directory" -ForegroundColor Green
New-Item -ItemType Directory $drive$pytnon_newWrite-Host "download Python" -ForegroundColor Green
wget -Uri $python_url$python_exe -UseBasicParsing -OutFile $drivec$python_exeWrite-Host "install Python" -ForegroundColor Green
Start-Process -FilePath $drivec\$python_exe -ArgumentList {/quiet TargetDir=C:\python InstallAllUsers=0 PrependPath=1 Include_test=0} -wait -PassThruWrite-Host "Python system path" -ForegroundColor Green
$env:path += ";C:\python"
$env:path += ";C:\python\Scripts"
setx PATH $env:path /MWrite-Host "Viewing Python the installation Directory" -ForegroundColor Green
where.exe pythonWrite-Host "check Python version" -ForegroundColor Green
python.exe --versionWrite-Host "check pip version" -ForegroundColor Green
pip.exe -VWrite-Host "download Python pip" -ForegroundColor Green
wget -Uri $pip_url$pip_py -UseBasicParsing -OutFile $drive$pip_pyWrite-Host "install pip" -ForegroundColor Green
python.exe $drive$pip_pyWrite-Host "install pip six psutil lxml pyopenssl" -ForegroundColor Green
pip install six psutil lxml pyopensslWrite-Host "delete Python pip_py" -ForegroundColor Green
Remove-Item $drive$python_exe -recurse
Remove-Item $drive$pip_py -recurse#Enterprise wechat robot address
$webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=XXXXXX"#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 = python.exe -V#pip version
$pip_version = pip -V#Get all IP addresses of the local host
$Win_ip = foreach($ipv4 in (ipconfig) -like '*IPv4*') { ($ipv4 -split ' : ')[-1]}#Get the host name
$Win_hostname = Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty Name#Gets the current host time
$Win_time = Get-Counter '\Processor(_Total)\% Processor Time' | Select-Object -ExpandProperty Timestamp$content = Write-Output ""Win_version: $Win_version_Names" `n "Win_host_ip: $Win_ip" `n "Win_hostname: $Win_hostname" `n "python_version: $python_version" `n "pip_version: $pip_version" `n "Win_time: $Win_time""$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.ps1
输出结果展示


企业微信机器人输出信息展示
- 获取系统版本
- 获取主机IP
- 获取主机名称
- 获取Python 版本
- 获取pip 版本
- 获取系统当前时间
