离线部署python环境及playwright

背景

最近开发需求,在客户内网客户端部署一套playwright环境,写脚本处理一些财务业务,电脑环境:win7 x64位

工具

  • python:3.7.8
  • playwright 1.15.3
  • Microsoft Visual C++ 2015-2019 Redistributable x64
  • Windows6.1-KB2533623-x64.msu

在python官网下载安装脚本时,支持win7的python版本最高是3.8。支持win7的playwright最高版本是1.15.3。其中补丁KB2533623-x64是解决win7安装python问题,vc_redist_x64解决运行playwright脚本报错。

本地安装

离线打包,首先需要创建同等环境做实验,操作系统不同支持的包会有一些差异导致安装失败。在本机准备win7虚拟机,安装python,playwright。然后迁移到内网进行安装部署。

# 安装playwright
pip install playwright==1.15.3

# 下载playwright自带浏览器
playwright install

下载过程中,可能会速度很慢,可以切换一下载资源地址:

pip install package_name -i https://pypi.tuna.tsinghua.edu.cn/simple/

离线安装python

# 导出本地python用到的库
pip freeze > requirements.txt
# 根据requirements.txt下载所需要的库
pip download -d packages -r requirements.txt

# 在内网安装
pip install --no-index --find-links=packages -r requirements.txt

上述packagesrequirements.txt文件夹和文件位置,都是相对于执行cmd时所在路劲的相对目录。

离线安装playwright

在执行 playwright install命令后,下载各种版本浏览器时,dos窗口会有一些下载路径。根据路径找到对应ms-playwright文件夹,里面chromium,firefox 和 webkit浏览器。直接把ms-playwright文件夹压缩迁移到内网,然后创建同等的文件夹。即可运行 playwright codegen开始调试、做试验。

# 安装时默认地址
C:\Users\用户名\AppData\Local\ms-playwright

# 测试playwright
playwright codegen

安装playwright效果:
在这里插入图片描述
执行playwright codegen效果:
在这里插入图片描述

总结

最先由于开发时,使用的win11,且安装playwright时,没有加版本号。默认下载的是1.35的版本。版本差异有一些,选择器支持的用法有点差异化。

参考链接

 - https://jiner.wang/win7%E5%AE%89%E8%A3%85-playwright-%E5%B8%B8%E8%A7%81%E7%9A%84%E9%97%AE%E9%A2%98/
 - http://www.360doc.com/content/12/0121/07/75507148_1074353724.shtml
 - https://blog.csdn.net/weixin_42794641/article/details/128660622
 - https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=net60#additional-deps
  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值