PowerShell Install Python 3.11.2
创始人
2025-05-31 13:34:10
0

Python 前言

  • Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。
  • Python 由 Guido van Rossum 于 1989 年底发明,第一个公开发行版发行于 1991 年。
  • 像 Perl 语言一样, Python 源代码同样遵循 GPL(GNU General Public License) 协议。

Python download

Pythondownload
pipdownload
Python 使用使用参数参考

前提条件

  • 开启wmi,配置网卡,参考 

 创建一键安装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 版本
  • 获取系统当前时间

相关内容

热门资讯

月之暗面几位出海产品负责人据悉... 11月12日消息,月之暗面几位出海产品负责人已于近期离职创业。今年9月,月之暗面决定停止更新两款已上...
中信证券:下半年新一轮增量政策... 11月12日消息,中信证券表示,财政扩张支持化债和保障性支出,货币政策宽松配合。经济增长依赖于循序渐...
特朗普预计将任命MARCO R... 11月12日消息,据报道,特朗普预计将任命MARCO RUBIO担任国务卿。
蚂蚁金服概念盘初活跃,君正集团... 11月12日消息,蚂蚁金服概念盘初活跃,君正集团2连板,金桥信息、浙大网新涨停,税友股份、合肥城建、...
宁德时代盘中涨超5%,成交额超... 11月12日消息,宁德时代盘中涨超5%,成交额超33亿元。
宽基ETF被抢筹,市场风格走向... 近期,股票市场震荡加剧,宽基类ETF(交易型开放式指数基金)的成交明显放量。截至12月17日,近一个...
价值10万的皮肤“到手价”仅6... 近日,围绕腾讯手游《金铲铲之战》(下称《金铲铲》)新赛季核心活动“不朽传奇召唤”的重大规则失误,一场...
成本3元卖60元,“99%高纯... 宣传“99%高纯”的产品,实测核心成分含量竟为0?近期,北京同仁堂一款南极磷虾油被质疑虚假宣传,在舆...
深夜,全线狂飙!美联储,突传重... 美股全线反攻!今晚,美股三大指数集体高开,纳指、标普500指数均大涨超1%,芯片股全线大涨,美光科技...
国盾量子公告:公司董事长吕品不... 科大国盾量子技术股份有限公司(以下简称“公司”)董事会沉痛公告,公司董事长吕品先生不幸逝世。吕品先生...