简体   繁体   English

如何在 Windows 上为 Anaconda 配置 Sublime Text 3?

[英]How to configure Sublime Text 3 for Anaconda on Windows?

I installed anaconda from the official website and I want to integrate it with sublime text 3. I tried to build a sublime-build json file like this:我从官方网站安装了 anaconda,我想将它与 sublime text 3 集成。我尝试构建一个 sublime-build json 文件,如下所示:

    {
    "cmd": ["C:/Users/Minh Duy/anaconda3/python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python"
    }   

But I got errors:但是我得到了错误:

C:\Users\Minh Duy\anaconda3\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "C:\Users\Minh Duy\anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
    from . import multiarray
  File "C:\Users\Minh Duy\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
    from . import overrides
  File "C:\Users\Minh Duy\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Minh Duy\Documents\Self-study\Python\Exercise\test_code.py", line 1, in <module>
    import numpy as np
  File "C:\Users\Minh Duy\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "C:\Users\Minh Duy\anaconda3\lib\site-packages\numpy\core\__init__.py", line 48, in <module>
    raise ImportError(msg)
ImportError:

I didn't add anaconda to PATH, but everything works fine on spyder and anaconda prompt.我没有将 anaconda 添加到 PATH,但在 spyder 和 anaconda 提示符下一切正常。 I don't really know if there is anything wrong with the way I set up anaconda or something else.我真的不知道我设置 anaconda 的方式是否有任何问题或其他问题。 Can someone help me with this issue?有人可以帮我解决这个问题吗?

The DLLs of the mkl-service that it's tried to load are by default located in the following directory:它尝试加载的 mkl 服务的 DLL 默认位于以下目录中:

C:/Users/<username>/anaconda3/Library/bin C:/Users/<用户名>/anaconda3/Library/bin

since that path isn't in the PATH Environment Variable, it can't find them and raises the ImportError.由于该路径不在 PATH 环境变量中,因此找不到它们并引发 ImportError。 To fix this, you can:要解决此问题,您可以:

  1. Add the mentioned path to the PATH Environment Variable: Open the start menu search, type env , click edit environment variables for your account , select path from the list at the top, click Edit then New, enter the mentioned path, and click OK.将提到的路径添加到 PATH 环境变量:打开开始菜单搜索,键入env ,点击编辑您帐户的环境变量,顶部列表中的 select 路径,单击编辑然后新建,输入提到的路径,然后单击确定。

This isn't the best method, as it makes this directory available globally, while you need it only when you are building with Anaconda.这不是最好的方法,因为它使该目录在全球范围内可用,而您仅在使用 Anaconda 构建时才需要它。

  1. Configure your custom Sublime Text build system to add the directory to PATH every time you use that build system (temporarily for the duration of that run).配置您的自定义 Sublime Text 构建系统以在每次使用该构建系统时将目录添加到 PATH(在该运行期间临时)。 This can be done simply by adding one line to the build system file, and it should look like this:这可以简单地通过在构建系统文件中添加一行来完成,它应该如下所示:
{
    "cmd": ["C:/Users/<username>/anaconda3/python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    "env": {
        "PYTHONIOENCODING": "utf-8",
        "PATH": "$PATH;C:/Users/<username>/anaconda3/Library/bin"},
}

This should work, however, to make it more error resistant you should consider adding some other paths too:然而,这应该有效,以使其更能抵抗错误,您也应该考虑添加一些其他路径:

  • C:/Users/<username>/anaconda3 C:/用户/<用户名>/anaconda3
  • C:/Users/<username>/anaconda3/Library/mingw-w64/bin C:/Users/<用户名>/anaconda3/Library/mingw-w64/bin
  • C:/Users/<username>/anaconda3/Library/usr/bin C:/Users/<用户名>/anaconda3/Library/usr/bin
  • C:/Users/<username>/anaconda3/Scripts C:/Users/<用户名>/anaconda3/Scripts
  • C:/Users/<username>/anaconda3/bin C:/用户/<用户名>/anaconda3/bin
  • C:/Users/<username>/anaconda3/condabi C:/用户/<用户名>/anaconda3/condabi
  1. If you have more than one Anaconda environment and want more control from inside Sublime Text, then you consider installing the Conda package for Sublime Text.如果你有多个 Anaconda 环境,并希望从 Sublime Text 内部获得更多控制,那么你可以考虑安装Conda package for Sublime Text。

Press Shift+Control+P to open command palette inside Sublime Text, search for Conda and click to install;按Shift+Control+P打开Sublime Text中的命令面板,搜索Conda并点击安装; once installed, change the build system to Conda from Menu -> Tools -> Build System.安装后,从菜单 -> 工具 -> 构建系统将构建系统更改为 Conda。 Then you can open the command palette and use the commands that start with Conda to manage your Anaconda Environments.然后您可以打开命令面板并使用以 Conda 开头的命令来管理您的 Anaconda 环境。

Note that you need to activate an environment before using Ctrl+B to build.注意在使用Ctrl+B构建之前需要先激活一个环境。

first configure it with python. write python in your cmd to get python path.首先用python配置它。在你的cmd中写入python以获得python路径。 then configure it with anaconda.然后用anaconda配置它。

{
"cmd": ["C:/Users/usr_name/AppData/Local/Programs/Python/Python37-32/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}

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

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