3

I have two Anaconda environments:

  • The base environment
  • An R environment (containing R only)

The base environment is the default environment and does not appear in the Anaconda subdirectory envs. Base is activated by default and in particular while the commands below are executed.

When I run python from within the Anaconda prompt (or another prompt that I have configured for Anaconda), importing numpy works without problems.

However, when I run my scrips from my IDE (exctuing C:\my\path\to\Anaconda3\python.exe myscript.py), the import of numpy fails. Therefore, I have installed numpy through pip and ended up with a broken installation. import numpy results now in

Traceback (most recent call last):
  File "D:\GoogleDrive\_Backup\Programmieren\Datathlon\econ_model.py", line 1, in <module>
    import numpy as np
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

As far as I know the issue is due to different versions of numpy being used. (I want the mkl-enabled version, though).

That the right version of numpy is not found lets me guess that I have multiple python environments somehow and that the wrong one is called by my IDE. I have no idea how this can be possible, as Anaconda is the only python resource on my PC.

How can I call the right python version from outside of the anaconda prompt? How can I configure python/Anaconda that the correct version is called by default?

I am aware that activating the base environment solves the problem when working within a shell. But if I run a single command, i.e. just call the python script without opening a shell before, I cannot activate anything (can I?).


Techincal details:

  • Python 3.7
  • conda version 4.6.8 win-64
  • Windows 10 64bit
  • IDE: Eclipse with PyDev
Samufi
  • 2,465
  • 3
  • 19
  • 43

3 Answers3

0

Have you tired activating the environments with a stack config? This allows my applications to use two different environments at the same time with different Python versions on each.

conda activate base && conda activate --stack myEnv
Chadd Frasier
  • 153
  • 1
  • 9
0

I had the same issue as yours, so I used the following command under "Run as Administrator" in my command prompt, and everything works fine thereafter

set CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1
Behzad
  • 121
  • 1
  • 16
-1

You can conda activate myEnvName. Then, calling python on shell will bring you the desired python. When installing packages, always select in which environment you wish it to be installed. The default environment is base

  • Thanks for the answer. As I said, base *is* active and was active when I installed the packages. In fact, everything works within the base environment from the anaconda prompt. So what is wrong in the case I described? – Samufi Apr 01 '19 at 17:33
  • Can you run it on shell and comment the output? `import numpy; print(numpy.__file__)` – Victor Hugo Borges Apr 01 '19 at 18:07
  • Sure. The output is `C:\my\path\to\Anaconda3\lib\site-packages\numpy\__init__.py` – Samufi Apr 01 '19 at 18:10
  • try `pip uninstall numpy`, then `conda install numpy`. Avoid using pip when you have conda. Also, check this solution: https://github.com/ContinuumIO/anaconda-issues/issues/1508#issuecomment-463227581 – Victor Hugo Borges Apr 01 '19 at 18:20
  • 1
    I have completed `conda install numpy` before even trying pip. As I said, numpy works well within the shell, but does *not* work outside the shell. – Samufi Apr 01 '19 at 18:23
  • after `pip uninstall numpy`, numpy is neither available within nor outside of the shell. `conda install numpy` tells me that numpy is already installed. I thus ran `conda remove numpy` and `conda install numpy` again. The result is that numpy is not available anywhere still, but anaconda tells me the package is installed... – Samufi Apr 01 '19 at 18:35
  • Try analyzing the difference between `import sys; print(sys.path)` in shell and inside you IDE. Also, check the path `C:\ProgramData\Anaconda3\lib\site-packages\` if numpy is installed there. – Victor Hugo Borges Apr 01 '19 at 18:42
  • `print(sys.path)` gives me exactly the same result when executed from within and outsinde of the shell. – Samufi Apr 01 '19 at 18:55
  • Maybe [this](https://stackoverflow.com/questions/54974444/pydev-eclipse-not-loading-mklinit-when-run-from-a-conda-environment) can help. It should be a problem with pydev. I recommend switch to vscode if you can. – Victor Hugo Borges Apr 01 '19 at 21:51
  • It is certainly not a PyDev issue, as the same problem occurs when I run the comman from cmd.exe or just use the run window (Win + R). I have now deleted and reinstalled Anaconda completely but run into other issues. – Samufi Apr 01 '19 at 22:03