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;
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.
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.
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).
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.
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"
}
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 :
From here, when you build the env, you can select conda if not selected:
** 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With