Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 332
Lucidnonsense Avatar asked Oct 07 '15 15:10

Lucidnonsense


People also ask

How do I run Python in Sublime Text 3?

To run the code, press Command B or go to Tools -> Build. As you can see, my Sublime Text is running Python 2.7. To change this to Python 3.7, we have to add a “Build System.”

How do I get Python to work with Sublime Text?

For language specific settings, click Sublime Text > Preferences > Settings - More > Syntax Specific - User. Then save the file using the following format: LANGUAGE. sublime-settings. For Python-specific settings, save the file as Python.


1 Answers

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.

like image 147
MattDMo Avatar answered Oct 06 '22 22:10

MattDMo