How to configure Sublime Text 3 for Anaconda?

风流意气都作罢 提交于 2020-04-16 04:49:32

问题


I download and install Anaconda2 from Anaconda Home. I registered Anaconda as my default Python2, but didn't add to my PATH. After this, I start Anaconda Prompt and everything is OK.

Now I want to use Anaconda with Sublime Text 3. After doing some search, I install the Anaconda plugin by Package Control. After that, I change 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 a appropriate Python.exe. It seems that I haven't choose my python interpreter, however I definitely set that in python_interpreter.

So I use 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 Anaconda Prompt.

So How can I solve all this problem and use ctrl+B to run my python code in Sublime Text 3.


回答1:


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.



来源:https://stackoverflow.com/questions/57068910/how-to-configure-sublime-text-3-for-anaconda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!