1

I downloaded and installed Anaconda 2 from Anaconda Home. I registered Anaconda as my default Python 2, but I didn't add it to my PATH. After this, I started the Anaconda Prompt and everything was OK.

Now I want to use Anaconda with Sublime Text 3. After doing some search, I installed the Anaconda plugin by Package Control. After that, I changed Anaconda's Default Setting like:

...
"python_interpreter": "E:\\Programs\\Anaconda2\\python.exe",
...

And User Setting like:

{
    "python_interpreter": "E:\\Programs\\Anaconda2\\python.exe",
    "swallow_startup_errors": true,
    "anaconda_linting": false,
}

According to my expectations, the following codes will print normally when I press Ctrl + B

import numpy as np
import pandas as pd

import sys
print "hello"

However, it prints out

'python' �����ڲ����ⲿ���Ҳ���ǿ����еij���
�����������

I don't know what it exactly means, so I run it in console, and it prints

>python F:/LOL/test.py
'python' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

These Chinese words means cmd can't find an appropriate Python.exe. It seems that I haven't chosen my Python interpreter. However, I definitely set that in python_interpreter.

So I use the full path, and it now prints out:

>E:\Programs\Anaconda2\pkgs\python-2.7.16-hcb6e200_0\python.exe
F:/LOL/test.py
Traceback (most recent call last):
  File "F:/LOL/test.py", line 1, in <module>
    import numpy as np
ImportError: No module named numpy

But NumPy is definitely installed. I can import it in the Anaconda Prompt.

So how can I solve all this problem and use Ctrl + B to run my Python code in Sublime Text 3?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
calvin
  • 2,125
  • 2
  • 21
  • 38
  • Im not sure what the issue is, but the chinese error it is throwing back is saying that python is not a recognizable command. Perhaps you can edit the "build with" options in sublimetext changing it to anaconda prompt – Axois Jul 17 '19 at 05:25
  • @Axois There is no Anaconda option in "Build with". Meanwhile, I am now using "Python" building system. As far as I know, after I installed the Sublime Text's Anaconda Plugin, it will somehow "take over" the original Python building system, and run in anaconda's context. So in my opinion, it's possible that cmd can't locate "Python.exe", but Sublime Text 3's ctrl+B should be able to locate Python, because I've already set `python_interpreter` – calvin Jul 17 '19 at 05:34

1 Answers1

4

It appears that you are using the wrong build system for your anaconda prompt. You can simply add in a build system by going to Tools->Build Systems->New Build System and enter the following json input

{
    "cmd": ["C:\\Users\\<<YOUR_NAME>>\\Anaconda3\\python.exe", "$file"],
    "selector": "source.python",
    "file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)"
}

You can replace the path with the path you have stored your python interpreter for anaconda.

The sublime-build file should be saved in \AppData\Roaming\Sublime Text 3\Packages\User with a .sublime-build extension with whatever name you want it to be.

You can then access it by Tools->Build Systems-> anaconda. This should point sublime to the correct interpreter. You can then force uninstall and reinstall numpy using the following command pip install --upgrade --force-reinstall numpy

I hope this solves your issue.

Axois
  • 1,961
  • 2
  • 11
  • 22
  • 1
    I tried, but it print out error like [this](https://paste.ubuntu.com/p/cXh4mdHD99/) – calvin Jul 17 '19 at 11:14
  • @calvin this is odd.. you can probably refer to [this](https://stackoverflow.com/questions/37096055/importing-numpy-results-in-error-even-though-anaconda-says-its-installed) I've got this feeling its your `PATH` thats the issue. You should probably check out your `PATH` to see if you have any conflicting python packages – Axois Jul 17 '19 at 12:10
  • @Axios Well, in this answer, pip is involved, however, I didn't install anything related to python. My computer was brand new before I install Anaconda2. Then install Anaconda at /Anaconda2/env/py3/, then I uninstall Anaconda3 because I think Anaconda3 is to blame, but nothing change. Since I didn't select "Add to PATH" option when installing and I didn't install Python before, I don't think there are any conflict here – calvin Jul 17 '19 at 12:19
  • @calvin have you tried reinstalling your numpy in anaconda prompt? You can do so using the following command `conda install -c anaconda numpy` – Axois Jul 17 '19 at 12:52
  • 2
    @calvin I think i might have found the solution to your problem. In your anaconda prompt type `pip install --upgrade --force-reinstall numpy` This forces to uninstall and reinstall the numpy package. I hope this works. – Axois Jul 18 '19 at 03:23