Using different conda envs with Sublime REPL

2019-05-11 08:37发布

I'm trying to set up Sublime Text 3 as a multilingual editor for doing data science.

For this I use Sublime REPL for executing code in Sublime, and intend to use Anaconda's (continuum analytics) built in virtual environments to make a venv for each project.

Unfortunately, the virtualenv option in Sublime REPL does not seem to support environments made with conda create.

By default it seems that Sublime REPL is using the root copy of python in anaconda, as it prints this information.

Python 3.5.1 |Anaconda 4.1.0 (x86_64)| (default, Jun 15 2016, 16:14:02) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

However, even trying fixes proposed by other questions: Sublime text3 and virtualenvs and How Do I Setup SublimeREPL with Anaconda's interpreter? once things are set up I get an error

PermissionError(13, 'Permission denied')

When I try to point at a virtual env created with conda create.

Is there any way to make Sublime REPL execute code with a particular conda environment? Or do I need to avoid the Anaconda distribution and use a manual install of python and virtualenv?

1条回答
我命由我不由天
2楼-- · 2019-05-11 09:10

This question might be a duplicate for this one.

As explained in the answer above, you can extend the list of usable python versions:

(Almost a) Quotation from the answer above:

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 - YourVirtualEnv",
                            "id": "repl_python",
                            "mnemonic": "p",
                            "args": {
                                "type": "subprocess",
                                "encoding": "utf8",
                                "cmd": ["/path/to/your/virtualenv/bin/yourPythonVersion", "-i", "-u"],
                                "cwd": "$file_path",
                                "syntax": "Packages/Python/Python.tmLanguage",
                                "external_id": "python",
                                "extend_env": {"PYTHONIOENCODING": "utf-8"}
                            }
                        },
                        {
                            "command": "repl_open",
                            "caption": "IPython - YourVirtualEnv",
                            "id": "repl_python_ipython",
                            "mnemonic": "p",
                            "args": {
                                "type": "subprocess",
                                "encoding": "utf8",
                                "autocomplete_server": true,
                                "cmd": ["/path/to/your/virtualenv/bin/yourIPythonVersion", "-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"
                                }
                            }
                        }
                    ]
                }
            ]
        }]
    }
]

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) or multiple virtualenvs you can just duplicate the children contents and alter the caption and cmd paths appropriately.

查看更多
登录 后发表回答