简体   繁体   中英

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:

    {
    "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. I don't really know if there is anything wrong with the way I set up anaconda or something else. 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:

C:/Users/<username>/anaconda3/Library/bin

since that path isn't in the PATH Environment Variable, it can't find them and raises the 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.

This isn't the best method, as it makes this directory available globally, while you need it only when you are building with 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). 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:/Users/<username>/anaconda3/Library/mingw-w64/bin
  • C:/Users/<username>/anaconda3/Library/usr/bin
  • C:/Users/<username>/anaconda3/Scripts
  • C:/Users/<username>/anaconda3/bin
  • C:/Users/<username>/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.

Press Shift+Control+P to open command palette inside Sublime Text, search for Conda and click to install; once installed, change the build system to Conda from Menu -> Tools -> Build System. Then you can open the command palette and use the commands that start with Conda to manage your Anaconda Environments.

Note that you need to activate an environment before using Ctrl+B to build.

first configure it with python. write python in your cmd to get python path. then configure it with 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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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