DjLint is not installed for the current active Python interpreter – How to Make djLint Available in All Virtual Environments in VS Code?

I have installed the djLint extension in VS Code and updated my settings file.

...
"[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
    "editor.defaultFormatter": "monosans.djlint"
  },
  "[django-html]": {
    "editor.defaultFormatter": "monosans.djlint",
    "editor.detectIndentation": true,
    "editor.formatOnSave": true,
    "editor.tabSize": 4,
    "djlint.profile": "django" // This will apply your custom profile
  },
 ...

However, when I create a new directory and set up a virtual environment (.venv), I get the following error when trying to save a Django template:

djLint is not installed for the current active Python interpreter. Install it with the `c:\Test\Django\Test\.venv\Scripts\python -m pip install -U djlint` command.

I want to avoid manually installing djLint in every virtual environment. Would appreciate any solutions or best practices. Thanks!

How about using requirements.txt ?

requirements.txt

djlint==1.36.4

Then run

$ pip install -r requirements.txt

After exploring the djLint VS Code extension repository, I found a way to make djLint available across all virtual environments without manually installing it in each one.

Using uv to Install djLint Globally

Instead of installing djLint in every virtual environment, I use uv, which is a faster and more efficient package manager. Here's how to set it up:

1. Install djLint using uv

uv tool install djlint

2. Update settings.json in VS Code

Modify your VS Code settings.json file to disable virtual environment dependency and specify the correct Python path:

{
"djlint.useVenv": false,
 // Linux Path 
"djlint.pythonPath":     "/home/user/.local/share/uv/tools/djlint/bin/python" 
// Windows Path
"djlint.pythonPath":"C:\\Users\\SRJ\\AppData\\Roaming\\uv\\tools\\djlint\\Scripts\\python" 
} 

If anyone has a better approach, feel free to share!

Вернуться на верх