Lucidnonsense
Lucidnonsense

Reputation: 1243

getting sublime text 3 to use anaconda python

So I've installed anaconda to a directory I have privileges for but I can't get sublime text 3 to recognise that the shell is now using anaconda python:

>which python
/local/home/USER/Apps/anaconda/bin/python

when I build with sublime launched from the same shell:

import astropy
print astropy.__file__

it gives a different directory: /soft/python-SL7/lib/python2.7/site-packages/astropy/init.pyc

My .tcshrc file reads:

setenv PATH /local/home/USER/Apps/anaconda/bin:${PATH}
alias subl /local/home/USER/Apps/sublime_text_3/sublime_text

My .bashrc (not that it should be using it) reads:

export PATH="/local/home/sread/Apps/anaconda/bin:$PATH"

Any ideas?

Upvotes: 6

Views: 14525

Answers (2)

Nicolay77
Nicolay77

Reputation: 2154

The other answer is correct, but you can also have a per project setting by editing the project file and adding this:

"build_systems":
[
    {
        "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
        "name": "Anaconda Python Builder",
        "selector": "source.python",
        "shell_cmd": "\"python3\" -u \"$file\""
    }
],

This also has the advantage of not leaving too many build systems in the build menu.

Upvotes: 1

MattDMo
MattDMo

Reputation: 102862

The easiest way is to create a new build system that points to your Anaconda installation. Create a new file in Sublime with JSON syntax and the following contents:

{
    "cmd": ["/local/home/USER/Apps/anaconda/bin/python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

Save the file in your Packages/User directory (should be ~/.config/sublime-text-3/Packages/User) as Anaconda.sublime-build. Finally, select Tools → Build System → Anaconda, and when you hit CtrlB in a Python file it should now run using Anaconda.

If you want to set up SublimeREPL to use Anaconda with IPython in Sublime, you can follow the instructions here to set up the proper menu option (altering the path to suit your environment, of course), and my gist here for setting up SublimeREPL for IPython 4 and Jupyter.

Upvotes: 15

Related Questions