Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Module load fails with Python 3.9.8 (undefined symbol _PyUnicode_DecodeUnicodeEscape) #169

Closed
rra opened this issue Nov 9, 2021 · 13 comments · Fixed by #171
Closed

Module load fails with Python 3.9.8 (undefined symbol _PyUnicode_DecodeUnicodeEscape) #169

rra opened this issue Nov 9, 2021 · 13 comments · Fixed by #171

Comments

@rra
Copy link

rra commented Nov 9, 2021

Attempting to import the module as installed from PyPI (x86_64 architecture) on Python 3.9.8 produces the following exception:

Traceback (most recent call last):
  File "/home/runner/.cache/pre-commit/repo8e93dzwn/py_env-python3/bin/black", line 5, in <module>
    from black import patched_main
  File "/home/runner/.cache/pre-commit/repo8e93dzwn/py_env-python3/lib/python3.9/site-packages/black/__init__.py", line 52, in <module>
    from typed_ast import ast3, ast27
  File "/home/runner/.cache/pre-commit/repo8e93dzwn/py_env-python3/lib/python3.9/site-packages/typed_ast/ast3.py", line 40, in <module>
    from typed_ast import _ast3
ImportError: /home/runner/.cache/pre-commit/repo8e93dzwn/py_env-python3/lib/python3.9/site-packages/typed_ast/_ast3.cpython-39-x86_64-linux-gnu.so: undefined symbol: _PyUnicode_DecodeUnicodeEscape

This appears to have broken between Python 3.9.7 and Python 3.9.8.

@rra
Copy link
Author

rra commented Nov 9, 2021

For others who may find this in a search, I ran into this problem via black because I had black pinned to an older version. The current version of black appears to no longer use typed-ast and thus won't encounter this issue.

@hroncok
Copy link
Contributor

hroncok commented Nov 10, 2021

diff --git a/ast3/Python/ast.c b/ast3/Python/ast.c
index cfca73f..93da89c 100644
--- a/ast3/Python/ast.c
+++ b/ast3/Python/ast.c
@@ -56,6 +56,8 @@ _PyBytes_DecodeEscape(const char *s,
     return PyBytes_DecodeEscape(s, len, errors, unicode, recode_encoding);
 }
 
+#endif
+
 PyObject *
 _PyUnicode_DecodeUnicodeEscape(const char *s,
                                Py_ssize_t size,
@@ -66,7 +68,6 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
     return PyUnicode_DecodeUnicodeEscape(s, size, errors);
 }
 
-#endif
 
 static int validate_stmts(asdl_seq *);
 static int validate_exprs(asdl_seq *, expr_context_ty, int);

This seems to get the job done.

@anthrotype
Copy link

I actually encountered this problem not while running black, but while running pytype. So what's the fix? Is there one?

anthrotype added a commit to googlefonts/nanoemoji that referenced this issue Nov 10, 2021
SimoRubi added a commit to SimoRubi/l10n-italy that referenced this issue Nov 10, 2021
ImportError: /home/runner/.cache/pre-commit/repob3mj_5qk/py_env-python3/lib/python3.9/site-packages/typed_ast/_ast3.cpython-39-x86_64-linux-gnu.so: undefined symbol: _PyUnicode_DecodeUnicodeEscape
The original issue is python/typed_ast#169
@rra
Copy link
Author

rra commented Nov 10, 2021

It looks like both mypy and black previously used typed-ast and no longer do. black at least (I haven't checked mypy) has switched to using the ast module included in Python for Python 3.8 and later. I suspect that's also the correct fix for pytype given #170.

@zerocewl
Copy link

The last workaround is using python@3.9.7...

@hauntsaninja
Copy link
Collaborator

Thanks for reporting, @hroncok are you willing to make a PR?

@hroncok
Copy link
Contributor

hroncok commented Nov 10, 2021

Here you go #171

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Nov 10, 2021

Specifically, when running on Python 3.8 and later, black / mypy will only use typed-ast to check / format Python 2 code. Recent releases of black / mypy have made Python 2 support an "extra", so they no longer install typed-ast on Python 3.8+ unless you do e.g. pip install "mypy[python2]".

I'm not sure what exactly pytype's usage of typed-ast looks like, but I imagine it could do something similar. Later today I'll make a release with a fix (thanks to hroncok!), in which case the solution will be to install that newly released typed-ast.

@anthrotype
Copy link

Many thanks for the quick fix! I have no idea what exactly pytype does with typed_ast, hopefully they will be able to sort it out like black and mypy have.

@steve-mavens
Copy link

steve-mavens commented Nov 11, 2021

Thanks for the fix! Do you have an ETA on when a release with this change might hit pypi? Not asking for any commitment, but I'm currently deciding whether or not to move to the latest black. If you're likely to release soon then I need not bother! :-)

@srittau
Copy link
Collaborator

srittau commented Nov 11, 2021

I believe @hauntsaninja wanted to do a release. If they have other commitments, I will see whether I can do a release today.

@steve-mavens
Copy link

steve-mavens commented Nov 11, 2021

That's fantastic, thank you. I've migrated one repo to the latest black, but this means I can leave the rest alone, since I don't think we need to do any other 3.9 builds imminently.

@hauntsaninja
Copy link
Collaborator

Released typed-ast 1.5.0 which includes this fix

copybara-service bot pushed a commit to google-deepmind/launchpad that referenced this issue Nov 15, 2021
…yped_ast#169).

PiperOrigin-RevId: 409928141
Change-Id: If4d6544047cccfe3014d3cde954973eed20cd422
rmorshea added a commit to rmorshea/pydocstyle that referenced this issue Dec 13, 2021
gnomesysadmins pushed a commit to GNOME/gobject-introspection that referenced this issue Feb 2, 2022
MSYS2 recently updated Python to 3.9.10 which triggered a build
issued present in typed_ast, which was fixed in typed_ast 1.5.0:
python/typed_ast#169

The currently used mypy version has an upper limit on typed_ast, so
this fixed version wasn't pulled in.

To fix this, update mypy, fix one new warning it complains about
(namedtuple not being named after the variable), and install the
markdown stubs explicitely, since mypy no longer bundles them.
jeffkala added a commit to jeffkala/nautobot-plugin-chatops-ansible that referenced this issue Jun 27, 2022
deantvv added a commit to deantvv/black-feedstock that referenced this issue Jul 26, 2022
typed-ast has an [issue](python/typed_ast#169 (comment))
which will lead to error: undefined symbol _PyUnicode_DecodeUnicodeEscape

They fix this error in `1.5.0`, so here comes the update.
deantvv added a commit to deantvv/black-feedstock that referenced this issue Jul 26, 2022
typed-ast has an [issue](python/typed_ast#169 (comment))
which will lead to error: undefined symbol _PyUnicode_DecodeUnicodeEscape

They fix this error in `1.5.0`, so here comes the update.
dragon-dxw added a commit to nhsx/nhsx-website that referenced this issue Dec 2, 2022
Black fails in CI:

```
Creating nhsx-website_test_run ... done
Traceback (most recent call last):
...
  File "/usr/lib/python3.9/site-packages/black/__init__.py", line 52, in <module>
    from typed_ast import ast3, ast27
  File "/usr/lib/python3.9/site-packages/typed_ast/ast3.py", line 40, in <module>
    from typed_ast import _ast3
ImportError: Error relocating /usr/lib/python3.9/site-packages/typed_ast/_ast3.cpython-39-x86_64-linux-musl.so: _PyUnicode_DecodeUnicodeEscape: symbol not found
```

https://stackoverflow.com/questions/69912264/python-3-9-8-fails-using-black-and-importing-typed-ast-ast3
python/typed_ast#169 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@srittau @rra @hroncok @anthrotype @zerocewl @hauntsaninja @steve-mavens and others