How to fix AttributeError: module βregexβ has no attribute βMatchβ for SQLFluff
In this blog post Iβll show you how to fix the AttributeError: module 'regex' has no attribute 'Match
error when trying to install SQLFluff.
SQLFluff is popular SQL linter and formatter. I ran into some issues when trying to install it.
Hopefully someone googles this error and then finds this post :)
Installing went fine
$ pip install sqlfluff
Collecting sqlfluff
...
Requirement already satisfied: regex in c:\users\janmeppe\anaconda3\lib\site-packages (from sqlfluff) (2021.4.4)
...
Successfully installed sqlfluff-0.11.1
And then I tried to follow the instructions but this happened
$ echo " SELECT a + b FROM tbl; " > test.sql
$ sqlfluff lint test.sql
Traceback (most recent call last):
...
File "c:\users\janmeppe\anaconda3\lib\site-packages\sqlfluff\core\templaters\slicers\tracer.py", line 389, in JinjaAnalyzer
self, m_open: regex.Match, m_close: regex.Match, tag_contents: List[str]
AttributeError: module 'regex' has no attribute 'Match
This has something to do with regex==2021.4.4
being broken. See also this github issue.
How I fixed it:
- Uninstall
regex==2021.4.4
- Upgrade
pip
- Install the most recent version of
regex
1) Uninstall regex
$ pip uninstall regex
Found existing installation: regex 2021.4.4
Uninstalling regex-2021.4.4:
Would remove:
c:\users\janmeppe\anaconda3\lib\site-packages\regex-2021.4.4.dist-info\*
c:\users\janmeppe\anaconda3\lib\site-packages\regex\*
Proceed (y/n)? y
Successfully uninstalled regex-2021.4.4
2) Upgrade pip
$ python -m pip install --upgrade pip
Collecting pip
Downloading ...
|ββββββββββββββββββββββββββββββββ| 2.1 MB 149 kB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.0.1
Uninstalling pip-21.0.1:
Successfully uninstalled pip-21.0.1
Successfully installed pip-22.0.4
3) Reinstall the most recent version of regex
$ pip install regex
...
Installing collected packages: regex
Successfully installed regex-2022.3.15
Should work now
$ sqlfluff
Usage: sqlfluff [OPTIONS] COMMAND [ARGS]...
Sqlfluff is a modular sql linter for humans.
Options:
--version Show the version and exit.
-h, --help Show this message and exit.
Commands:
dialects Show the current dialects available.
fix Fix SQL files.
lint Lint SQL files via passing a list of files or using stdin.
parse Parse SQL files and just spit out the result.
rules Show the current rules in use.
version Show the version of sqlfluff.
Hope this helps!
Comments