ZyzotPerplex
ZyzotPerplex

Reputation: 11

Anaconda Python environment not activated when running from SublimeText3 SublimeREPL package

I am using SublimeText3 with the SublimeREPL package and the Miniconda python installation. I have followed the instructions listed here to run python from SublimeText3 with a custom environment:

How Do I Setup SublimeREPL with Anaconda's interpreter?

Yet, when I run the Python interpreter from SublimeText3, I initially get

Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

If I then try to

import numpy

I get the following error message:

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\USER\Miniconda3\envs\CUSTOM_ENV\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\USER\Miniconda3\envs\CUSTOM_ENV\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.

For other packages such as sympy, I don't get an error when I try to import the package. Similarly, if I run anaconda from the anaconda prompt and import numpy, it runs without errors.

So it seems that it is calling python from the custom environment but thinks the environment isn't activated and can't load Numpy.

Cross-posted here:

https://github.com/wuub/SublimeREPL/issues/576

Upvotes: 1

Views: 2296

Answers (2)

Psychotechnopath
Psychotechnopath

Reputation: 2744

A simple hotfix for this is to reinstall miniconda, and tick the option add to path. When miniconda is on your path, IDE's like sublime automatically activate your environment. Another option is to launch anaconda prompt, activate your environment, and then launch sublime from that prompt.

Upvotes: 3

Roland Weber
Roland Weber

Reputation: 3655

The instructions you followed are questionable. They tell Sublime to use Python from the Anaconda environment, but they do not activate that environment. Nowadays, Anaconda does some environment checking, which was not the case back in 2013 when that answer was given.

Write a batch file CUSTOM_ENV_python.bat like this:

conda activate CUSTOM_ENV
python

then configure Sublime to call that batch file instead of Python.

I'm not familiar with Windows batch programming, so you might have to tweak the commands above a bit. Test the batch file from a command line first. Once it works there, configure Sublime accordingly.

Upvotes: 0

Related Questions