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 版本
  • 获取系统当前时间

相关内容

热门资讯

【内网安全】 隧道搭建穿透上线... 文章目录内网穿透-Ngrok-入门-上线1、服务端配置:2、客户端连接服务端ÿ...
【Spring Cloud A... 文章目录前言Metadata元数据ClassMetadataSpring中常见的一些元注解Nacos...
React篇-关于React的... 一.简介1.介绍用于构建用户界面的 JavaScript 库2.创建项目(1)手动创建Documen...
win7 Pro 英文版添加中... win7pro x64英文版添加中文语言包1、下载语言包,并解压成lp.cab,复制到...
Android开发-Andro... 01  Android UI 1.1  UI 用户界面(User Interface,...
基于springboot教师人... 基于springboot教师人事档案管理系统【源码+论文】 开发语言:Jav...
编写软件界面的方式 本文重点解决如下问题:编写软件的界面有哪几种方式?通常情形下࿰...
keil调试专题篇 调试的前提是需要连接调试器比如STLINK。 然后点击菜单或者快捷图标均可进入调试模式。 如果前面...
GO语言小锤硬磕十三、数组与切... 数组用来保存一组相同类型的数据,go语言数组也分一维数组和多维数组。 直接上代码看一下...
三级数据库备考--数据库应用系... 1.数据库应用系统设计包括概念设计、逻辑设计、物理设计3个步骤,每个步骤的设计活动按照...
prometheus数据持久化... https://segmentfault.com/a/1190000015710814 promet...
孩子用什么样的灯对眼睛没有伤害... 现代社会高速发展,越来越多的人开始重视身体健康,尤其是很多家长ÿ...
微软Bing GPT支持AI绘... 我想要一张图片:大象、珊瑚、火山、云朵我想要一张图片:亚特兰蒂斯...
最新!5月IPO受理数创今年新... IPO市场新动态。5月30日,共有4家IPO企业获得受理,其中创业板打破今年“0受理”现象,迎来首批...
Stable diffusio... Stable Diffusion是对Latent Diffusion模型的改进,主要在以下方面进行了...
Linux命令_lsof 网... 官方描述         一个打开的文件可以是一个常规文件、一个目录、一个块特殊文件、一个字符特殊...
树状数组(区间维护/单点修改) 1,定义 数组数组用于维护区间信息,简洁的几行的代码可以单点操作/区间查...
Junit4 + Mockit... ​ 实战代码案例: 1,引入依赖 org.spr...
Linux 增加用户 user... 在Linux中增加用户是用useradd指令指令基本选项useradd [option] usern...
2023年全国最新安全员精选真... 百分百题库提供安全员考试试题、建筑安全员考试预测题、建筑安全员ABC考试真题、安全员证考试题库等&#...