Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default Python interpreter in Sublime text 3

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;

like image 480
user3682213 Avatar asked May 28 '14 05:05

user3682213


People also ask

How do I configure Python interpreter in 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.

How do I replace Python in Sublime Text?

Now go to Tools -> Build System, and select Python3 (or whatever you named your Build System). If you don't see your new build system, you may have to quit Sublime Text and reopen it. Now run the same code to test which version of Python you're using. There you go, Python 3.7 up and running.

What is the default Python interpreter?

By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).

Does Sublime Text have Python interpreter?

With Sublime repl, you press ctrl+b to start the code into a python interpreter inside sublime text itself, so that you do not have to open the cmd.


2 Answers

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"
}
like image 54
Daniel Rasmuson Avatar answered Sep 30 '22 03:09

Daniel Rasmuson


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.

like image 40
Rohit Kumar J Avatar answered Sep 30 '22 04:09

Rohit Kumar J