Sublime Forum

Use Sublime Text with Python conda environments

#1

I’m a macOS user and have Python installed via Miniconda which is basically a lightweight version of Anaconda. All of my Python development is done within conda environments. These environments have different Python packages installed based on the project that the environment is for.

For writing my Python code, I use Sublime Text 4 with the LSP-pylsp package. I launch Sublime Text from the terminal where the Python environment is already active. Sometimes things like autocompletion, displaying docstrings, and other LSP functionality work fine. But other times I don’t get any autocompletion or docstring support in Python files. So it seems like Sublime Text does not recognize certain activated conda environments. I tried the settings shown below in my .sublime-project file but it doesn’t fix my issue.

{
    "python_binary": "/opt/miniconda3/envs/myproj/bin/python",
    "folders":
    [
        {
            "path": "."
        }
    ],
    "settings": {
        "LSP": {
            "LSP-pylsp": {
                "settings": {
                    "pylsp.plugins.jedi.environment": "/opt/miniconda3/envs/myproj"
                }
            }
        }
    }
}

And here is my LSP-pylsp.sublime-settings file.

{
    "settings": {
        "pylsp.configurationSources": [
            "flake8"
        ],
        "pylsp.plugins.pycodestyle.enabled": false,
        "pylsp.plugins.flake8.enabled": true,
        "pylsp.plugins.flake8.maxLineLength": 120,
        "pylsp.plugins.pylsp_black.enabled": true,
    }
}

Is there something else I need to configure to make sure Sublime Text is using the activated conda environment? And how can I tell which conda environment it is using?

0 Likes

#2

Were you able to get this working? I’ve been running into this issue as well, trying to work with condo environments and the LSP based completion, but have yet to find out how to get this to work

0 Likes

#3

That depends on the LSP server you use.

0 Likes