简体   繁体   English

获取 sublime text 3 以使用 anaconda python

[英]getting sublime text 3 to use anaconda python

So I've installed anaconda to a directory I have privileges for but I can't get sublime text 3 to recognise that the shell is now using anaconda python:所以我已经将 anaconda 安装到我有权限的目录中,但我无法获得 sublime text 3 来识别 shell 现在正在使用 anaconda python:

>which python
/local/home/USER/Apps/anaconda/bin/python

when I build with sublime launched from the same shell:当我使用从同一个 shell 启动的 sublime 进行构建时:

import astropy
print astropy.__file__

it gives a different directory: /soft/python-SL7/lib/python2.7/site-packages/astropy/ init .pyc它提供了不同目录:/soft/python-SL7/lib/python2.7/site-packages/astropy/初始化.pyc文件

My .tcshrc file reads:我的 .tcshrc 文件显示:

setenv PATH /local/home/USER/Apps/anaconda/bin:${PATH}
alias subl /local/home/USER/Apps/sublime_text_3/sublime_text

My .bashrc (not that it should be using it) reads:我的 .bashrc (不是它应该使用它)显示:

export PATH="/local/home/sread/Apps/anaconda/bin:$PATH"

Any ideas?有任何想法吗?

The easiest way is to create a new build system that points to your Anaconda installation.最简单的方法是创建一个指向 Anaconda 安装的新构建系统 Create a new file in Sublime with JSON syntax and the following contents:使用 JSON 语法和以下内容在 Sublime 中创建一个新文件:

{
    "cmd": ["/local/home/USER/Apps/anaconda/bin/python", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
}

Save the file in your Packages/User directory (should be ~/.config/sublime-text-3/Packages/User ) as Anaconda.sublime-build .将文件保存在你的Packages/User目录(应该是~/.config/sublime-text-3/Packages/User )作为Anaconda.sublime-build Finally, select Tools → Build System → Anaconda , and when you hit Ctrl B in a Python file it should now run using Anaconda.最后,选择Tools → Build System → Anaconda ,当您在 Python 文件中按 Ctrl B 时,它现在应该使用 Anaconda 运行。

If you want to set up SublimeREPL to use Anaconda with IPython in Sublime, you can follow the instructions here to set up the proper menu option (altering the path to suit your environment, of course), and my gist here for setting up SublimeREPL for IPython 4 and Jupyter.如果您想设置SublimeREPL以在 Sublime 中使用 Anaconda 和 IPython,您可以按照此处的说明设置正确的菜单选项(当然,更改路径以适合您的环境),以及我在此处设置 SublimeREPL 的要点IPython 4 和 Jupyter。

The other answer is correct, but you can also have a per project setting by editing the project file and adding this:另一个答案是正确的,但您也可以通过编辑项目文件并添加以下内容来设置每个项目:

"build_systems":
[
    {
        "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
        "name": "Anaconda Python Builder",
        "selector": "source.python",
        "shell_cmd": "\"python3\" -u \"$file\""
    }
],

This also has the advantage of not leaving too many build systems in the build menu.这还有一个好处是不会在构建菜单中留下太多构建系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM