Import numpy error

I cannot import numpy inside 3-matic. I can import it in pycharm and spyder and control 3-matic externally just fine, but would like to be able to use numpy from 3-matic. Because I can import it elsewhere, I think this is an error with how 3-matic is attempting to import the module. I am also starting an issue with numpy on github; in case the error is on their side.

import numpy as np

Traceback (most recent call last):

File “C:\Users\Npyle1.conda\envs\3mat\lib\site-packages\numpy\core_init_.py”, line 17, in
from . import multiarray
File “C:\Users\Npyle1.conda\envs\3mat\lib\site-packages\numpy\core\multiarray.py”, line 14, in
from . import overrides
File “C:\Users\Npyle1.conda\envs\3mat\lib\site-packages\numpy\core\overrides.py”, line 7, in
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\Npyle1.conda\envs\3mat\lib\site-packages\numpy_init_.py”, line 142, in
from . import core
File “C:\Users\Npyle1.conda\envs\3mat\lib\site-packages\numpy\core_init_.py”, line 47, in
raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.

  • Try uninstalling and reinstalling numpy.
  • If you have already done that, then:
    1. Check that you expected to use Python3.7 from “C:\Program Files\Materialise\3-matic 14.0 (x64)\3-matic.exe”,
      and that you have no directories in your PATH or PYTHONPATH that can
      interfere with the Python and numpy version “1.17.1” you’re trying to use.
    2. If (1) looks fine, you can open a new issue at
      https://github.com/numpy/numpy/issues. Please include details on:
      • how you installed Python
      • how you installed numpy
      • your operating system
      • whether or not you have multiple versions of Python installed
      • if you built from source, your compiler versions and ideally a build log

Original error was: DLL load failed: The specified module could not be found.

Hello Nathaniel,

I see that you are using Conda.
MIS v.20.0–22.0 does not support Conda’s virtual Python environments out-of-the-box.

However, in you case with import numpy there exists a workaround, which can scripted.

Please add this snippet at the start of your script (or, to be precise - before importing numpy or similar):

import os
import sys

env_p = sys.prefix  # path to the env
print("Env. path: {}".format(env_p))

new_p = ''
for extra_p in (r"Library\mingw-w64\bin",
    r"Library\usr\bin",
    r"Library\bin",
    r"Scripts",
    r"bin"):
    new_p +=  os.path.join(env_p, extra_p) + ';'

os.environ["PATH"] = new_p + os.environ["PATH"]  # set it for Python
os.putenv("PATH", os.environ["PATH"])  # push it at the OS level

We expect it to work for the both 3-matic and Mimics.
If not, please try not to use Conda’s virtual environments, but conventional Python.

Best regards, Vladimir

PS: it has been tested against MIS v.22.0 and Conda 4.7.10:

2019-10-11_17h00_02

Hello Vladimir,

I just realized I never thanked you. That snippet solved my problem. I will say that, because I’m doing other program development along with working with mimics and 3matic, conda is an invaluable tool for me. If Materialise could build in better interfacing with conda, that’d be quite wonderful.