ImaginePhoenix
ImaginePhoenix

Reputation: 65

Cannot use Ananconda Interpreter in Sublime Text 3

I want to use Sublime Text 3 as my Python editor but cannot figure out how to make Anaconda its default interpreter for Python. To make sure that Anaconda is added to the path correctly, in the terminal I typed

$ which python

Terminal returns

/home/rahit/anaconda3/bin/python

But when I type a code like this in ST 3

import sys
print(sys.executable)

The output in the Sublime console will be

/usr/bin/python

Now if I type

import pandas as pd

There will be always an error

ImportError: No module named pandas [Finished in 0.0s with exit code 1] [shell_cmd: python -u "/home/rahit/Documents/Python/pro.py"] [dir: /home/rahit/Documents/Python] [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/> usr/local/games:/opt/jdk-11.0.2/bin]`

Apart from these whenever I launch Sublime Text 3, many a times I get a message saying

<Anaconda.anaconda_lib.workers.local_process.LocalProcess object at 0x7f248c4eab90> process can not start a new anaconda JsonServer in the operating system because:

Anaconda can not spawn a new process with your current configured python interpreter (/home/rahit/anaconda/bin/python) Make sure your interpreter is a valid binary and is in your PATH or use an absolute path to it, for example: /usr/bin/python

I have seen there are already some questions asked on these topic but none of them actually solved my problem. I have also seen people similar discussions on github from which I have ended up concluding that Conda cannot be used with ST3. For the final time I just want to know if there is any way to fix this problem cause I really want to use ST3 for Python.

Upvotes: 1

Views: 6821

Answers (2)

vassis
vassis

Reputation: 173

Complementing @Shadesfear's answer, to use this custom build you have to select either Tools ▶ Build System ▶ Automatic or Tools ▶ Build System ▶ <your-custom-build-system-name> before building your code.

Also, you can replace the cmd command with "shell_cmd": "~/anaconda3/bin/python -u $file", at your .sublime-build file because it is cleanner and allow you to use pipes.

Upvotes: 0

Shadesfear
Shadesfear

Reputation: 749

That is because of the build system that sublime uses, it uses your default python executable.

If you go to Tools ▶ Build System ▶ New Build System… and then you can define your own build system that uses the anaconda executable. It should look like the following

{
    'cmd': ['/usr/bin/python3', '-u', '$file'],
    'file_regex': '^[ ]*File "(…*?)", line ([0-9]*)',
    'selector': 'source.python'
}

Then just replace the path with the path of your anaconda executable

Upvotes: 1

Related Questions