22

I am currently using the Anaconda python distribution for my project (NOT the anaconda plugin, they have the same name, but the one I am using includes Numpy, IPython, etc. It is kinda confusing). So I want to change the default python (v3.3) to the one in Anaconda (v2.7.6), in that case I will be able to use the libraries embedded in Anaconda. I tried to put a new script under Tool > Build System > New Build System.

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

But it failed, the sublime is still using the default interpreter:

>>>print (sys.version)
3.3.0 (default, Jun 12 2013, 17:01:35) 
[GCC 4.7.2]
>>> print (sys.executable)
python3
>>> print (sys.path)
['/opt/sublime_text', '/opt/sublime_text/python3.3.zip', '/home/username/.config/sublime-text-3/Packages']

So my question is quite simple (but hard enough for one who doesn't know): How to change this default python interpreter to the one I want;

user3682213
  • 323
  • 1
  • 2
  • 5
  • It looks like you're using an internal console. Changing the build system isn't going to change Sublime Text 3's personal version of Python. Can you try executing [a script](http://stackoverflow.com/questions/1252163/printing-python-version-in-output) to test the version number in interpreted files instead? – angerson May 28 '14 at 11:34
  • You are right, I was using the internal console. I just create the script and run it using "ctrl + B", and the output tells me the version is 2.7.6 and the version of python is under /home/myname/anaconda/bin/python (which is exactly what I am expecting for). But I am not sure how that happen cause I am no longer use the new added "Build System" but the default one. – user3682213 May 28 '14 at 16:03
  • Since I can use the my ideal 2.7.6 python to execute my code, I think the only problem left is how to use this 2.7.6 python interpreter as my interactive console and not 3.3 that is running right now. Many thanks! – user3682213 May 28 '14 at 16:09
  • Great! You might like SublimeREPL. https://github.com/wuub/SublimeREPL – angerson May 30 '14 at 15:11

2 Answers2

6

You can get it working by distinguishing the name of python.

For example change

C:\Python27\python.exe 

to

C:\Python27\python2.exe

Change your environment variables to reference this change. Type python2 in cmd to confirm its working.

And then you should be able to reference this from your build hotkey.

{
"path": "/home/username/anaconda/bin",
"cmd": ["python2", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Dan Rasmuson
  • 5,705
  • 5
  • 29
  • 45
2

Extremely Simple Method :

You can get sublime-text-conda via the package manager: Ctrl+shift+ P Serach for conda, once installed, you need to activate or create the environments within sublimetext to change environment: Ctrl+shift+ P, and type: conda :

conda functions in context

From here, when you build the env, you can select conda if not selected:

enter image description here

** I've noticed that if I switched to a conda env form package control, and selected a different build system, then the build system doesn't switch back when you re-select conda via package control, might wanna check this if you switch between build systems.

Rohit Kumar J
  • 87
  • 1
  • 8