1. 适用场景
一键部署python,并配置环境变量,
注·:本文暂且只适用于windows主机的一键部署.
2. 操作流程
2.1 免费下载工具包:
https://download.youkuaiyun.com/download/zize_snail/89220798
解压后文件内容如下图,此处的python版本为3.6.8
2.2 右击管理员执行 install.bat 批处理文件
到此已经完成python的安装和全局变量的设置啦!
注:python会默认安装在C盘。
3.脚本全貌
3.1 install.bat脚本内容
@echo off
cd /d "%~dp0"
setlocal
:: check administrator
NET SESSION >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
ECHO Administrator PRIVILEGES Detected!
) ELSE (
ECHO 请右键选择以管理员形式运行!
pause
)
:: 安装Python
ECHO 安装Python
start /wait "" python-3.6.8-amd64 /quiet InstallAllUsers=1 PrependPath=1
:: 等待安装完成
timeout /t 30
:: 更新系统变量
for /f "delims=" %%p in ('where python') do set "PYTHON_DIR=%%p"
setx PATH "%PYTHON_DIR%;%PATH%"
endlocal
echo 完成Python与全局变量配置。
echo 开始安装依赖包
:: pip install --no-index --find-links=./packages -r requirements.txt
pause
3.2 更改python版本包
如果更改python版本包,install.bat中python包名也要更改哦!
3.3 批量安装依赖包
方式一:联网部署,将包名保存在requirements.txt文件中,并执行以下指令:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
注:requirements.txt文件的内容参考如下:
allure-pytest==2.12.0
allure-python-commons==2.12.0
atomicwrites==1.4.1
方式二:离线部署依赖包:可参考该文章:https://blog.youkuaiyun.com/zize_snail/article/details/137641951