0

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?

  • 1
    This doesn't look like an issue with Anaconda the Python distribution or Anaconda the Sublime plugin (the two are completely unrelated, BTW). The first line of the error tells you exactly what's wrong - you need to either reinstall `numpy` or add the `mkl-service` module, as `numpy` seems to depend on it. – MattDMo Oct 25 '20 at 19:03
  • Does this answer your question? [numpy is already installed with Anaconda but I get an ImportError (DLL load failed: The specified module could not be found)](https://stackoverflow.com/questions/54063285/numpy-is-already-installed-with-anaconda-but-i-get-an-importerror-dll-load-fail) – AMC Oct 26 '20 at 00:09

2 Answers2

2

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.

Ewindar
  • 21
  • 6
-1

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"
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Roohullah Kazmi
  • 337
  • 3
  • 14
  • Why did you change the `cmd` path to Python? That's not what the issue is at all. – MattDMo Oct 25 '20 at 19:00
  • I used my own python path. you use your own. I think the problem is you are directly configuring it to anaconda. first configure it with python and then anaconda. – Roohullah Kazmi Oct 28 '20 at 14:12
  • What does that even mean? The OP is using the Anaconda Python distribution, so if they want to use the Anaconda Python modules, they need to use the Anaconda Python interpreter. They may not even have another Python distribution (like the one from python.org) installed, so your advice makes absolutely no sense. If you actually read the error message they're getting, `numpy` isn't working because `mkl-service` isn't installed. Changing the path to a potentially non-existent location isn't going to do anything except give a WinError 2: File not found. – MattDMo Oct 28 '20 at 18:02