I have installed the Anaconda
plugin in Sublime Text Build 4126 and it doesn't work its autocomplete function. I don't know why. Anaconda's linting works indeed.
Python version: 3.10
Could you help please to detect and fix the problem?
I have installed the Anaconda
plugin in Sublime Text Build 4126 and it doesn't work its autocomplete function. I don't know why. Anaconda's linting works indeed.
Python version: 3.10
Could you help please to detect and fix the problem?
Since I wrote this answer, Anaconda has been updated to fix the problem. If you haven't already, simply update your Anaconda installation to v2.3.0 or newer.
The Anaconda
plugin comes with several other Python libraries bundled in, including jedi
(for autocompletion), autopep8
for code formatting, and several others. These libs are part of the Anaconda
plugin itself, and are not installed as Package Control dependencies, so their versions don't change unless the plugin's author, DamnWidget, updates them manually. However, as they explained in a recent comment, they haven't used Python or Sublime Text for a while, and are maintaining the plugin simply because it's popular with the community and no one else has stepped up to maintain it.
One of the included libraries is parso
, which parses Python source using a grammar file specific for the version of Python being used. This plugin happens to be where the bugs that are causing your problem lie. The first issue is that the included version of parso
, which was last updated in May 2020, does not have grammar files for Python 3.10 (or beyond). (The grammar file for 3.9 is also exactly the same as the one for 3.8, but we'll fix that as well.) The second issue is that even if there were a 3.10 grammar file included, the parso
source (and hence Anaconda
), wouldn't be able to read it, so you don't get autocomplete.
We'll need to follow several steps to fix both these issues.
Open your Sublime Text Packages
folder by clicking on Preferences → Browse Packages…
. Depending on your OS and whether or not you installed ST4 fresh or upgraded from ST3, this folder will be in different locations:
~/.config/sublime-text-3/Packages
or ~/.config/sublime-text/Packages
~/Library/Application Support/Sublime Text 3/Packages
or ~/Library/Application Support/Sublime Text/Packages
C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
or C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
InstallationFolder\Sublime Text 3\Data\Packages
or InstallationFolder\Sublime Text\Data\Packages
Open your Command Prompt, Powershell, or Terminal and navigate to a temporary directory, such as C:\Temp
on Windows or /tmp
on macOS or Linux.
Type in:
git clone https://github.com/davidhalter/parso.git
Alternatively, if you use a separate source control GUI program, use it to clone that repository someplace like one of the temp directories I mentioned.
Enter the just-created parso
directory, then go into the parso/python
directory. You'll see that among the files there are the grammarXX[X].txt
files, where XX[X]
starts at 36
and goes up to 312
. Open this folder in your operating system's file explorer app to make copying and pasting easier. Select all of the grammar files and copy them.
Back in the Packages
window we opened earlier, navigate to Anaconda/anaconda_lib/parso/python
. Paste the copied grammar files here. You'll be overwriting some of them, but that's okay - we want to do that. This will fix the first problem you're having.
Navigate up one level, so that your file explorer location is now Packages/Anaconda/anaconda_lib/parso
. Open the file called utils.py
in Sublime and navigate down to line 123. It should look like this:
match = re.match(r'(\d+)(?:\.(\d)(?:\.\d+)?)?$', version)
We're going to add exactly one character. Replace the original line with this (make sure it's indented 4 spaces):
match = re.match(r'(\d+)(?:\.(\d+)(?:\.\d+)?)?$', version)
# ^ added this
Save the file, and you're done! Restart Sublime Text, and Anaconda autocomplete should now work with versions 3.10 and above!
Please keep in mind that your changes will be overwritten the next time Anaconda is upgraded, but hopefully the next time that happens the new version will fix these bugs.