【问题标题】:getting sublime text 3 to use anaconda python获取 sublime text 3 以使用 anaconda python
【发布时间】:2016-01-04 23:07:33
【问题描述】:

所以我已将 anaconda 安装到我有权限的目录中,但我无法获得 sublime text 3 来识别 shell 现在正在使用 anaconda python:

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

当我使用从同一个 shell 启动的 sublime 构建时:

import astropy
print astropy.__file__

它给出了一个不同的目录:/soft/python-SL7/lib/python2.7/site-packages/astropy/init.pyc

我的 .tcshrc 文件内容如下:

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

我的 .bashrc(不是应该使用它)内容如下:

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

有什么想法吗?

【问题讨论】:

    标签: python linux sublimetext3


    【解决方案1】:

    最简单的方法是创建一个新的build system 指向您的 Anaconda 安装。使用 JSON 语法和以下内容在 Sublime 中创建一个新文件:

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

    将文件保存在Packages/User 目录(应为~/.config/sublime-text-3/Packages/User)中为Anaconda.sublime-build。最后,选择 Tools → Build System → Anaconda,当您在 Python 文件中按 CtrlB 时,它现在应该使用 Anaconda 运行。

    如果你想设置 SublimeREPL 在 Sublime 中使用 Anaconda 和 IPython,你可以按照说明 here 设置正确的菜单选项(当然,改变路径以适应你的环境),我的gist here 为 IPython 4 和 Jupyter 设置 SublimeREPL。

    【讨论】:

    • 这对我不起作用。我复制粘贴你的答案只是为了确保。我还用["which", "python"]["which", "/local/home/USER/Apps/anaconda/bin/python"]. Both cmds return /local/home/USER/Apps/anaconda/bin/python. So the shell is correct it just keeps importing from /soft/python-SL7/lib/python2.7/site-packages 替换了cmd`
    • 此外,当我尝试pip install astropy --update 时,它会说它安装了以前的版本。这有关系吗?
    • @Lucidnonsense 就pip 而言,pip -V 返回什么?它应该告诉你它与哪个 python 可执行文件相关联。对于另一个问题,您是在.tcshrc.bashrc 中设置PYTHONPATH 变量吗?
    • 我设法以某种方式解决了这个问题。我不知道怎么做。 (pip -V 返回 anaconda 路径)。谢谢
    • 我仍然无法让它工作。可能崇高不会调用命令“conda activate base”。我们怎么能这样做?
    【解决方案2】:

    另一个答案是正确的,但您也可以通过编辑项目文件并添加以下内容来进行每个项目的设置:

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

    这还有一个好处是不会在构建菜单中留下太多构建系统。

    【讨论】:

    • 这完全不同。这是一个由Anaconda Sublime 包自动创建的构建系统,它与 OP 使用的 Anaconda Python 发行版没有任何关系。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    相关资源
    最近更新 更多