Linux配置playwright环境
datehoer 10/25/2023 pythoncentosplaywright
找了一台旧的服务器,想要用来跑python的playwright脚本,然而发现环境太旧了,所以记录一下更新环境的记录。
首先是安装python,这里没有选择使用anaconda安装,而是直接通过官网 (opens new window)下载源码编译安装的。
之后利用pip安装playwright
pip install playwright
playwright install
1
2
2
会出现类似下面的错误
/usr/lib/playwright/chromium-920619/chrome-linux/chrome:
/lib64/libc.so.6: version `GLIBC_2.18' not found (required by /usr/lib/playwright/chromium-920619/chrome-linux/chrome)
1
2
2
这里又要去安装GLIBC_2.18
wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar zxf glibc-2.28.tar.gz
cd glibc-2.28/
mkdir build
cd build/
../configure --prefix=/usr/local/glibc-2.28
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
会报错
These critical programs are missing or too old: make compiler
1
去升级又会遇到新的错误
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
1
然后去升级make (opens new window)、gawk、bison、gcc (opens new window)、MPC (opens new window)、GMP (opens new window)、MPFR (opens new window)之后就可以正常编译GLIBC_2.18了
大体的升级流程都是下面这样的
yum install -y bison
yum install -y gawk
wget xxx.tar.gz
tar -xvf xxx
./configure --prefix=/usr/local/xxx
make && make install
gcc
[root@sss ~]# cd gcc-10.2.0/
[root@sss gcc-10.2.0]# mkdir build && cd build
[root@sss build]# ../configure --prefix=/usr/local/gcc-10.2.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-1.0.3
[root@sss build]# make && make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
然后就可以正常的playwright install
但是启动一个测试脚本还是会出错
from playwright.sync_api import sync_playwright, Playwright
def run(playwright: Playwright):
chromium = playwright.chromium
browser = chromium.launch()
page = browser.new_page()
page.goto("http://google.com")
print(page.title())
browser.close()
with sync_playwright() as playwright:
run(playwright)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Host system is missing dependencies to run browsers. ║
║ Missing libraries: ║
║ libatk-1.0.so.0 ║
║ libatk-bridge-2.0.so.0 ║
║ libxcb.so.1 ║
║ libxkbcommon.so.0 ║
║ libatspi.so.0 ║
║ libX11.so.6 ║
║ libXcomposite.so.1 ║
║ libXdamage.so.1 ║
║ libXext.so.6 ║
║ libXfixes.so.3 ║
║ libXrandr.so.2 ║
║ libgbm.so.1 ║
║ libpango-1.0.so.0 ║
║ libcairo.so.2 ║
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
yum -y install libappindicator-gtk3
yum -y install liberation-fonts
1
2
2
然后这里遇到了一个问题
sudo yum -y install libappindicator-gtk3
Failed to set locale, defaulting to C
error: rpmdb: BDB0113 Thread/process 8200/140391818810624 failed: BDB1507 Thread died in Berkeley DB library
error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db5 - (-30973)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:
Error: rpmdb open failed
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
这是因为RPM数据库损坏,进行删除重建即可。
sudo cp -ar /var/lib/rpm /var/lib/rpm.backup
sudo rm -f /var/lib/rpm/__db*
sudo rpm --rebuilddb
sudo yum clean all
sudo yum -y install libappindicator-gtk3
1
2
3
4
5
2
3
4
5
之后再次执行就可以了
$ python3.9 test.py
Google
1
2
2