How Do I Setup SublimeREPL with Anaconda's interpreter?

后端 未结 2 1070
遇见更好的自我
遇见更好的自我 2020-11-29 23:46

I love Python in Sublimetext, but what I really need is an interactive mode for data exploration. However, for the life of me I cannot get SublimeREPL to use Anaconda\'s int

相关标签:
2条回答
  • 2020-11-30 00:07

    In your Packages/User folder, create SublimeREPL/config/Python/Main.sublime-menu with the following contents:

    [
        {
            "id": "tools",
            "children":
            [{
                "caption": "SublimeREPL",
                "mnemonic": "r",
                "id": "SublimeREPL",
                "children":
                [
                    {
                        "caption": "Python",
                        "id": "Python",
    
                        "children":[
                            {
                                "command": "repl_open",
                                "caption": "Python - Anaconda",
                                "id": "repl_python",
                                "mnemonic": "p",
                                "args": {
                                    "type": "subprocess",
                                    "encoding": "utf8",
                                    "cmd": ["/path/to/Anaconda/python", "-i", "-u"],
                                    "cwd": "$file_path",
                                    "syntax": "Packages/Python/Python.tmLanguage",
                                    "external_id": "python",
                                    "extend_env": {"PYTHONIOENCODING": "utf-8"}
                                }
                            },
                            {
                                "command": "repl_open",
                                "caption": "IPython - Anaconda",
                                "id": "repl_python_ipython",
                                "mnemonic": "p",
                                "args": {
                                    "type": "subprocess",
                                    "encoding": "utf8",
                                    "autocomplete_server": true,
                                    "cmd": ["/path/to/Anaconda/python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                                    "cwd": "$file_path",
                                    "syntax": "Packages/Python/Python.tmLanguage",
                                    "external_id": "python",
                                    "extend_env": {
                                        "PYTHONIOENCODING": "utf-8",
                                        "SUBLIMEREPL_EDITOR": "$editor"
                                    }
                                }
                            }
                        ]
                    }
                ]
            }]
        }
    ]
    

    In the "cmd" lines, change /path/to/Anaconda/python with the actual path to your python executable you want to use. If you're on Windows, either use a single / as path delimiter, or double \\:

    c:/Anaconda/bin/python.exe
    # or
    c:\\Anaconda\\bin\\python.exe
    

    Save the file, and you should now have Tools -> SublimeREPL -> Python -> Python - Anaconda and IPython - Anaconda menu options to start REPLs with the Anaconda interpreter. If you have multiple versions of Python installed (for example, 2.7 and 3.3) you can just duplicate the children contents and alter the caption and cmd paths appropriately.

    0 讨论(0)
  • 2020-11-30 00:09

    With the caveat that this is an old question with an accepted answer that makes your problem go away, it doesn't directly answer your question. (I would have made this a comment but I don't have sufficient reputation.)

    The reason your user settings line doesn't work is because you're specifying the path incorrectly. You are not including a slash before Users, so it's a relative path and not absolute, and you are also giving the full path to the Python binary, not the directory containing the binary. Rewriting what you have to:

    {
        "default_extend_env": {"PATH": "/Users/anton/anaconda/envs/py3k/bin:{PATH}"}
    }
    

    should solve your problem. Furthermore, I believe it is best practice to copy the contents of the Default SublimeREPL settings file to the user settings file, and then to add the default_extend_env line at the end.

    0 讨论(0)
提交回复
热议问题