[BUG] Unable to run script past import
Context:
- Playwright Version: 1.29.1
- Operating System: Windows
- Python version: 3.11
- Browser: n/a
Code Snippet
from playwright.sync_api import Page, expect
from classes.pages.login.page_login import PageLogin
def test_login_successful_login(page: Page):
username = "student"
password = "Password123"
# etc
Error encountered
Traceback (most recent call last):
File "C:\Workspace\Testing\Test_Environment\main.py", line 1, in <module>
from playwright.sync_api import Page, expect
File "C:\Workspace\Testing\Test_Environment\venv\Lib\site-packages\playwright\sync_api\__init__.py", line 25, in <module>
import playwright.sync_api._generated
File "C:\Workspace\Testing\Test_Environment\venv\Lib\site-packages\playwright\sync_api\_generated.py", line 25, in <module>
from playwright._impl._accessibility import Accessibility as AccessibilityImpl
File "C:\Workspace\Testing\Test_Environment\venv\Lib\site-packages\playwright\_impl\_accessibility.py", line 17, in <module>
from playwright._impl._connection import Channel
File "C:\Workspace\Testing\Test_Environment\venv\Lib\site-packages\playwright\_impl\_connection.py", line 23, in <module>
from greenlet import greenlet
File "C:\Workspace\Testing\Test_Environment\venv\Lib\site-packages\greenlet\__init__.py", line 29, in <module>
from ._greenlet import _C_API # pylint:disable=no-name-in-module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: DLL load failed while importing _greenlet: The specified module could not be found.
Continued (for some reason this was being cut off)
I have googled as much as I can, doesn't seem to be much help on this issue.
To sanity check, I used the codegen to go to google.com and encountered the same issue with this code:
from playwright.sync_api import Playwright, sync_playwright, expect
def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("https://www.google.com/")
# ---------------------
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)```
Could you confirm you have 64 Bit of Python installed? You can find it out the following way:
- type just
pythoninto the console which opens a REPL - enter
exit()to exit it.
Then show us the output which was shown which contains e.g. [MSC v.1934 64 bit (AMD64)] on win32 on my machine.
This is what I get:
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
Over many hours today, I have been installing different versions of pycharm, python and playwright. I even tried a fresh user but still got this error.
I did manage to get a basic script to run with python 3.9 and playwright 1.26.0
But I would really like to start this new project with 1.29.1 and python 3.11
Edit: I noticed that 1.26.0 using greenlet 1.1.3 and 1.29.1 uses 2.0.1. Maybe that is useful info
Most likely it has something to do with the environment. I'm also running Python 3.11.1 and for me it works without any issues.
Sorry for the trouble and I'm running out of ideas.
Sorry for the delay,
Did some further testing and I get the issue in 1.28
python 3.9 with:
- 1.26 - browser opens, all good
- 1.27 - browser opens, all good
- 1.27.1 - browser opens, all good
- 1.28 - errors, greenlet etc
- 1.29 - errors, greenlet etc
- 1.30 - errors, greenlet etc
For right now, I am stuck on version 1.27/1.27.1 - something happened in 1.28 which is failing
To be fair, I don't even need to have any active test code in there, just the import fails: from playwright.sync_api import Playwright, sync_playwright
Don't know if these are relavent: windows version 10.0.19044 Build 19044 Pip version: 22.3.1
Greenlet just released a new version which contains some fixes, we will upgrade to it soon. You can manually try to upgrade to it via:
pip install greenlet==2.0.2
Might be worth to try. Otherwise try filing an issue against greenlet itself, they know their library better than we do.
Worth trying, but unfortunately it didn't work
Any idea what changed between 1.27.1 and 1.28 that could have caused this?
Yes we upgraded from greenlet v1 to v2 to support Python 3.11+. So its definitely caused by something on their end.
I installed greenlet 1.1.3 for playwright 1.30 and this is working with python 3.9
I will raise an issue with greenlet, pointing them here, but I suggest you guys also do the same as I don't have any technical knowlege when it comes to the playwright, greenlet library or the differences between 3.9 and 3.11 (except for performance and switch case support)
Hi! I actually have the same problem. I tried jfp's solution and it actually works! I am using python 3.8 and it works without any problem. Altough it would be great for this to be fixed this is a good temporary solution.
Everything worked fine with my main pc but not on my old laptop that I use as a server.
@mxschmitt Could it be a difference between MS home and pro? This work laptop(where failure is) uses pro
Issue created on greenlet: https://github.com/python-greenlet/greenlet/issues/346
Cool, closing this one then, since this is not a Playwright issue. You also already got a response in the greenet repository which suggests that this is also not caused by Greenlet, maybe try to re-install Python?
Try pip install msvc-runtime
Try
pip install msvc-runtime
It Worked for me!
Another user ran into it, and he had to install these libraries:
https://aka.ms/vs/17/release/vc_redist.x64.exe https://aka.ms/vs/17/release/vc_redist.x86.exe