Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zetavg/aef569377bd209dd0c4bf7111f8b17cc to your computer and use it in GitHub Desktop.
Save zetavg/aef569377bd209dd0c4bf7111f8b17cc to your computer and use it in GitHub Desktop.
Configure Sublime Text LSP-pyright to Use the Conda Env for a Project

Configure Sublime Text LSP-pyright to Use the Conda Env for a Project

First, use the command conda info --envs to find the path of a specific environment created with conda.

$ conda info --envs
# conda environments:
#
base                     /Users/z/miniconda3
some-env              *  /Users/z/miniconda3/envs/some-env
some-other-env           /Users/z/miniconda3/envs/some-other-env

For example, /Users/z/miniconda3/envs/some-env.

Then, edit the Sublime Text project (top menu bar: ProjectEdit Project), and add the following in the settings:

{
  "LSP": {
    "LSP-pyright": {
      "enabled": true,
      "settings": {
        "python.pythonPath": "<conda_env_path>/bin/python"
      }
    }
  }
}

Such as:

 // See https://www.sublimetext.com/docs/projects.html

 {
   "folders": [
     {
       "path": "/Users/z/Projects/SomeFolder",
       // "name": "",
       "folder_exclude_patterns": [],
       "file_exclude_patterns": [],
       "binary_file_patterns": ["*.build", "*.build*", "*.bundle", "*.bundle*", "*.idx", "*.ipa", "*.pcm"],
       "follow_symlinks": true
     }
   ],
   "settings": {
+    "LSP": {
+      "LSP-pyright": {
+        "enabled": true,
+        "settings": {
+          "python.pythonPath": "/Users/z/miniconda3/envs/some-env/bin/python"
+        }
+      }
+    },
   },
 }

Restart LSP-pyright if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment