Closed DaBrondo closed 3 years ago
First time with playwright for me and I've received the same error:
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'm using Ubuntu 20.04 through WSL (version 2) and I installed playwright inside a virtualenv using:
$ pip install playwright
$ python -m playwright install
Please make sure you are using playwright==1.8.0a1 since the docs were all updated to match our v1 offering.
I'll make sure our samples for installation suggest that explicitly. Sorry for inconvenience!
Thank you for help @pavelfeldman May be useful to tell explicitly also that the are also some dependencies not installed using:
$ pip install playwright
$ python -m playwright install
I don't know if this is a situation related only to WSL or not but I got this message:
playwright._impl._api_types.Error: Host system is missing dependencies!
Install missing packages with:
sudo apt-get install libnss3\
libnspr4\
libatk1.0-0\
libatk-bridge2.0-0\
libcups2\
libxkbcommon0\
libgbm1\
libgtk-3-0\
libpango-1.0-0\
libcairo2\
libgdk-pixbuf2.0-0\
libatspi2.0-0
PS: I think the suggested command (apt-get install ...
) needs a whitespace after each package name to work. (see below)
-- edit (I got also this):
playwright._impl._api_types.Error: Host system is missing dependencies!
Install missing packages with:
sudo apt-get install libegl1 \
libnotify4 \
libvpx6 \
libopus0 \
libwoff1 \
libharfbuzz-icu0 \
libgstreamer-plugins-base1.0-0 \
libgstreamer-gl1.0-0 \
libgstreamer-plugins-bad1.0-0 \
libopenjp2-7 \
libwebpdemux2 \
libenchant1c2a \
libsecret-1-0 \
libhyphen0 \
libgles2 \
gstreamer1.0-libav
It looks like the original issue has been resolved and a new one filed for dependencies. Closing.
Hi, I'm unsuccessfully trying to use playwright. I've got this error:
ImportError: cannot import name 'sync_playwright' from 'playwright' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/playwright/__init__.py)
though I've installed playwright using this command:
pip install playwright==1.8.0a1
Please help me solve the issue. Thanks!
I have the same issue. When I run
from playwright import sync_playwright
I'll get
ImportError: cannot import name 'sync_playwright' from 'playwright' (/home/matej/.pyenv/versions/myenv/lib/python3.8/site-packages/playwright/__init__.py)
also here is the content of __init__
file
__pdoc__ = {
"_accessibility": False,
"_async_base": False,
"_browser": False,
"_browser_context": False,
"_browser_type": False,
"_cdp_session": False,
"_chromium_browser_context": False,
"_connection": False,
"_console_message": False,
"_dialog": False,
"_download": False,
"_element_handle": False,
"_event_context_manager": False,
"_file_chooser": False,
"_frame": False,
"_helper": False,
"_impl_to_api_mapping": False,
"_input": False,
"_js_handle": False,
"_main": False,
"_network": False,
"_object_factory": False,
"_page": False,
"_path_utils": False,
"_playwright": False,
"_selectors": False,
"_sync_base": False,
"_transport": False,
"_wait_helper": False,
"_async_playwright": False,
"_sync_playwright": False,
}
When i run from terminal playwright codegen
it works
Update: The whole issue was using outdated import statement. It should be
from playwright.sync_api import sync_playwright
I am having this same problem, what should I do?
cannot import name 'sync_playwright' from 'playwright.sync_api'
I can run it somedays ago,but when i update mac os to the latest.It is wrong
I am still facing the same issue with the below import statement
from playwright.sync_api import sync_playwright
but when I change it to from playwright import sync_playwright
i don't get the import error
Hi, bumping this. One issue I have is that it does not look like there is a playwright==1.8.0a1
version anymore for use with python3? I get a no version error when doing pip3
but not pip
. So does this imply the package will only work in python2?
& error I'm getting on sublime
I'm facing same issue on Windows 10, I've tried all suggestions in this thread. Please help
CODE: import re
import playwright
from playwright import sync_playwright def run(playwright: sync_playwright) -> None: browser = playwright.chromium.launch(headless=False) context = browser.new_context() page = context.new_page() page.goto("https://www.edinburghlive.co.uk/newsletter-preference-centre/?utm_source=newslettersignupheader") page.get_by_role("heading", name="News", exact=True).click() page.get_by_role("button", name="Subscribe").first.click() page.get_by_role("button", name="close-icon").click() page.close()
# ---------------------
context.close()
browser.close()
with sync_playwright() as playwright: run(playwright)
ERROR:
Traceback (most recent call last):
File "d:\Python\PlayWright\example2.py", line 7, in
@ShawnJorge try the following: https://github.com/python-greenlet/greenlet/issues/346#issuecomment-1416918053
I receive this error when running the sync example code:
ImportError: cannot import name 'sync_playwright' from 'playwright.sync_api'
I've used venv to create a Python3 virtual environment and playwright installed via pip into that environment.