I am trying to use sqlfluff
linter, which is a SQL formatter and linter. In settings.json I have, among others, this:
"[sql]": {
"editor.defaultFormatter": "dorzey.vscode-sqlfluff" // Use SQLFluff formatter
},
"editor.formatOnSave": true,
"workbench.settings.applyToAllProfiles": [],
"python.defaultInterpreterPath": "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12" // Enable auto-formatting on save
I am using MacBook and when I press save on a SQL file I get:
Traceback (most recent call last):
File "/opt/homebrew/bin/sqlfluff", line 8, in <module>
sys.exit(cli())
^ ^^^^
File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^ ^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^ ^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^ ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^...
/opt/homebrew/lib/python3.11
is not the python library I want it to use, which is /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12
.
I tried:
Python: Select Interpreter
(real path and virtual env)From the terminal, I get the correct version of python
:
nir@mac % python -V
Python 3.12.8
nir@mac % which python
python: aliased to python3
nir@mac % which python3
/Library/Frameworks/Python.framework/Versions/3.12/bin/python3
sqlfluff
however, I do not get the right version in the terminal:
nir@mac % which sqlfluff
/opt/homebrew/bin/sqlfluff
nir@mac % sqlfluff version
2.3.5
In my pyproject.tomal I have:
dependencies = [
"sqlfluff==3.3.0",
...
]
I needed to set the extension's path in setting.json:
"sqlfluff.env.environmentVariables": [
{
"key": "PATH",
"value": "/Users/nir/venvs/python/bin/"
}
]