'Can't import name 'sync_playwright' from 'playwright.sync_api' on MacOS and ubutunOS
I'm trying import playwright framework. However, I faced an issue as below:
Traceback (most recent call last):
File "simple.py", line 1, in <module>
from playwright.sync_api import sync_playwright
ImportError: cannot import name 'sync_playwright' from 'playwright.sync_api' (/home/acid/dev/play/venv
/lib/python3.8/site-packages/playwright/sync_api.py)
I've installed the playwright by command below:
pip install playwright==1.8.0a1
playwright install
Then, run script:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = browser_type.launch()
page = browser.new_page()
page.goto('http://whatsmyuseragent.org/')
page.screenshot(path=f'example-{browser_type.name}.png')
browser.close()
However, it still didn't work. Do you have any suggest for this issue? Thank in advances
Solution 1:[1]
Referencing this:
-
pip install --upgrade pip
-
pip uninstall playwright
-
pip install playwright
Change to your script directory
-
playwright install
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mike |