Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot persuade Black Formatter to forget old anaconda-based setup. #552

Closed
njlivesey opened this issue Jan 3, 2025 · 5 comments
Closed
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue is not triaged.

Comments

@njlivesey
Copy link

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): python 3.12 via miniforge/conda version 24.7.1
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): miniforge mamba
  • Operating system (and version): Local is MacOS 14.7.2. Remote is Linux (Oracle I think, 4.18.0-553.27.1.el8_10.x86_64)
  • Version of tool extension you are using: 2024.4.0

Behaviour

Expected Behavior

Black formatter to work as before (though I recall having problems making it work under anaconda)

Actual Behavior

I switched from anaconda to miniforge on my remote linux machine and the black-formatter doesn't work. When I do "Black Formatter: Restart Server" a window pops up saying:

Command 'Black Formatter: Restart Server' resulted in an error
Failed to resolve env "/users/livesey/anaconda3/envs/njl-base-3.10-18oct23/bin/python"

The above path is the outdated (and removed) anaconda environment. I've tried switching from useBundled to fromEnvironment, no impact.

I've pasted the logs from when I do the "Restart Server" below. They seem clean and error-free enough to me.

Reproduction Steps:

Logs:

2025-01-02 17:21:27.723 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.723 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/python/lxgp
2025-01-02 17:21:27.725 [info] Interpreter from ms-python.python extension for /users/livesey/python/lxgp: /users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python
2025-01-02 17:21:27.725 [info] Workspace settings for /users/livesey/python/lxgp (client side): {
"cwd": "/users/livesey/python/lxgp",
"workspace": "file:///users/livesey/python/lxgp",
"args": [],
"path": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/black"
],
"interpreter": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python"
],
"importStrategy": "useBundled",
"showNotifications": "off"
}
2025-01-02 17:21:27.725 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.725 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/a-smls/asmls-gds
2025-01-02 17:21:27.725 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.726 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/python/dualpy
2025-01-02 17:21:27.727 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.727 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/proposals/roses-uaco-2024/figures-source
2025-01-02 17:21:27.727 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.727 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/python/lxgp
2025-01-02 17:21:27.727 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.727 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/python/madart
2025-01-02 17:21:27.728 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.728 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/python/mls-scf-tools
2025-01-02 17:21:27.728 [info] No interpreter found from setting black-formatter.interpreter
2025-01-02 17:21:27.728 [info] Getting interpreter from ms-python.python extension for workspace /users/livesey/python/moepy
2025-01-02 17:21:27.733 [info] Interpreter from ms-python.python extension for /users/livesey/a-smls/asmls-gds: /users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python
2025-01-02 17:21:27.733 [info] Workspace settings for /users/livesey/a-smls/asmls-gds (client side): {
"cwd": "/users/livesey/a-smls/asmls-gds",
"workspace": "file:///users/livesey/a-smls/asmls-gds",
"args": [],
"path": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/black"
],
"interpreter": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python"
],
"importStrategy": "useBundled",
"showNotifications": "off"
}
2025-01-02 17:21:27.733 [info] Interpreter from ms-python.python extension for /users/livesey/proposals/roses-uaco-2024/figures-source: /users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python
2025-01-02 17:21:27.733 [info] Workspace settings for /users/livesey/proposals/roses-uaco-2024/figures-source (client side): {
"cwd": "/users/livesey/proposals/roses-uaco-2024/figures-source",
"workspace": "file:///users/livesey/proposals/roses-uaco-2024/figures-source",
"args": [],
"path": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/black"
],
"interpreter": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python"
],
"importStrategy": "useBundled",
"showNotifications": "off"
}
2025-01-02 17:21:27.733 [info] Interpreter from ms-python.python extension for /users/livesey/python/lxgp: /users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python
2025-01-02 17:21:27.733 [info] Workspace settings for /users/livesey/python/lxgp (client side): {
"cwd": "/users/livesey/python/lxgp",
"workspace": "file:///users/livesey/python/lxgp",
"args": [],
"path": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/black"
],
"interpreter": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python"
],
"importStrategy": "useBundled",
"showNotifications": "off"
}
2025-01-02 17:21:27.733 [info] Interpreter from ms-python.python extension for /users/livesey/python/madart: /users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python
2025-01-02 17:21:27.733 [info] Workspace settings for /users/livesey/python/madart (client side): {
"cwd": "/users/livesey/python/madart",
"workspace": "file:///users/livesey/python/madart",
"args": [],
"path": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/black"
],
"interpreter": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python"
],
"importStrategy": "fromEnvironment",
"showNotifications": "off"
}
2025-01-02 17:21:27.733 [info] Interpreter from ms-python.python extension for /users/livesey/python/moepy: /users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python
2025-01-02 17:21:27.733 [info] Workspace settings for /users/livesey/python/moepy (client side): {
"cwd": "/users/livesey/python/moepy",
"workspace": "file:///users/livesey/python/moepy",
"args": [],
"path": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/black"
],
"interpreter": [
"/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python"
],
"importStrategy": "useBundled",
"showNotifications": "off"
}

Outcome When Attempting Debugging Steps:

When I type "black <filename.py>" on the remote machine it runs fine.

Extra Details

As I say, I recall having to do something hard-coding like when I was running anaconda. Perhaps that's got stuck in its memory. However, I can find no references to the anaconda path in any of my settings.json files. Is there somewhere else I should look?

I installed this extension after having run an older black-like extension (I forget whose). Perhaps there's something lingering from that.

@njlivesey njlivesey added the bug Issue identified by VS Code Team member as probable bug label Jan 3, 2025
@github-actions github-actions bot added the triage-needed Issue is not triaged. label Jan 3, 2025
@njlivesey
Copy link
Author

Quick note. As a (temporary?) work around, I was finally able to get it working by adding the following to settings.json on the remote side:

{
    "black-formatter.importStrategy": "fromEnvironment",
    "black-formatter.interpreter": [
        "/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/python"
    ],
    "black-formatter.path": [
        "/users/livesey/.conda/envs/njl-base-3.12-02jan25/bin/black"
    ]
}

@njlivesey
Copy link
Author

OK, and I've just had the same experience with the pylint VSCode extension, and the same fix worked.
It seems this is perhaps something related to the python extension and/or VSCode install itself, but I welcome any wisdom in this forum.

@hourlier96
Copy link

Hi,

I had kind of the same problem but with pyenv tool.

VSCode maintains internal caches of interpreters.

I fixed the problem by:

  • Open Command Palette (Cmd+Shift+P).
  • Select Python: Clear Workspace Interpreter Settings.
    This will remove cached interpreter references for the current workspace, and so, black won't look for them anymore.

@njlivesey
Copy link
Author

njlivesey commented Jan 13, 2025 via email

@eleanorjboyd
Copy link
Member

Hi! Seems resolved, please comment and I can reopen if not. Thanks

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue is not triaged.
Projects
None yet
Development

No branches or pull requests

3 participants