Forums

Playwright chromium install failed.

I'm trying to install playwright using

python -m pip install playwright

which yielded success, but when I try to install the browser binary with

python -m playwright install

but I got the following:

Downloading Playwright build of chromium v907428 - 126 Mb [====================] 100% 0.0s 
Failed to install browsers
Error: Failed to download chromium v907428, caused by
Error: EIO: i/o error, write

I tried again for a few times and now the error changed to:

Removing unused browser at /home/hcaptcha/.cache/ms-playwright/chromium-907428
Downloading Playwright build of chromium v907428 - 126 Mb [====================] 100% 0.0s 
Failed to install browsers
Error: Failed to download chromium v907428, caused by
Error: ENOENT: no such file or directory, mkdir '/home/hcaptcha/.cache/ms-playwright/chromium- 
907428/chrome-linux/ClearKeyCdm/'.

I also tried install only chromium as one can do so per the documentation:

playwright install chromium

but got the same error. Any help? I'm using python 3.9.5 virtual env.

I don't think playwright will work on PythonAnywhere. We have a help page about using selenium here

I found a workaround for this, turns out pythonanywhere comes with a chromium binary preinstalled.

could you please explain how did you find this workaround?

pythonanywhere has a chromium binary preinstalled at /usr/bin/chromium.

So could you please give me the steps to make playwright work properly?

Set the executable path for the browser:

browser = playwright.chromium.launch(executable_path='/usr/bin/chromium')

Tips:

You can optionally disable GPU acceleration which I found give it better performance on a gpu-less runtime.

browser = playwright.chromium.launch(executable_path='/usr/bin/chromium', args=['--disable-gpu'])

Thanks, You saved my day

I still have this error though : net::ERR_TUNNEL_CONNECTION_FAILED at https://ent.ensa-tetouan.ac.ma/?home/index

I see you're trying to connect to a website via playwright. You have to ask the admin to whitelist the website. See https://help.pythonanywhere.com/pages/RequestingAllowlistAdditions

You will also find all the required chromium arguments here

when I try setting the executable path for the browser using
browser = playwright.chromium.launch(executable_path='/usr/bin/chromium')

I get the following error
bash: syntax error near unexpected token `('

It's been a while since the last post on this thread, but I'd like to add a sincere "thanks!" to @hcaptcha for the suggestion. We now have a help page for Playwright that includes their suggestion, and has some minimal code to help people get started.

In case it is useful to staff: Not seen this thread until now, but I've had no problems at all using playwright without any tweaks in a Python 3.10 venv on 'haggis', i.e. equivalent of this just worked, and I've used it several times to update the browser:

$ workon venv310
$ pip install -r requirements.txt  # contains `playwright==1.44.0 ; python_version >= "3.10" and python_version < "4.0"`
$ playwright install chromium  # ignored if not required
$ playwright --version
Version 1.44.0

And then actual code includes:

    with sync_playwright() as p:
        _log_info("Launching browser", start_time)
        browser = p.chromium.launch()
        page = browser.new_page()
        ...

Should I change things?

Edit: this is on an EU server, maybe that's relevant.

Interesting! Perhaps the install chromium command used to always try to install it, but now it doesn't if it can find one already installed?

If you've got it up and running and it's all working OK, then I don't think you need to change anything, no.