-1

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:

  1. Reinstall the extension
  2. Set it in 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",
...
]
6
  • What does sqlfluff look like? Commented Jan 22 at 8:43
  • What do you mean? Commented Jan 22 at 8:52
  • What are the first few lines of sqlfluff? Commented Jan 22 at 8:54
  • I dont understand what you are asking. First lines of what? it is a linter, you press save on any file .sql file and it formats it. Commented Jan 22 at 8:59
  • 1
    An extension might not read the Python interpreter location from that specific setting you showed (very common). So, read the instructions from the extension authors and see if you missed important tips. If the issue remains after trying to follow those, report this as a bug to the authors. Many VS Code extensions are hosted on GitHub, and it shouldn’t be hard to locate the issue tracker. Commented Jan 22 at 9:27

1 Answer 1

0

I needed to set the extension's path in setting.json:

"sqlfluff.env.environmentVariables": [
        {
            "key": "PATH",
            "value": "/Users/nir/venvs/python/bin/"
        }
    ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.