How To Fix The Error Undefined Variable From Import: Array In Windows LiClipse

This article will tell you how to produce the undefined variable from import: array error and how to fix it. It will also tell you how to fix the error 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.

1. How To Produce The Undefined Variable From Import: Array Error.

  1. The below method is just the method that produces the undefined variable from import: array error in my environment, your produce method may not be the same.
  2. I use LiClipse & Anaconda to develop my python examples. And when I open the existing python project in LiClipse, it shows the error message like Undefined Variable From Import: Array in the source code. I find the code that throws this error is just created a Numpy array, so this error is must a Numpy related error.
  3. When I right-click the python source code in LiClipse and then click the Run As —> Python Run menu item to run it, it throws the below error message in the LiClipse Console.
    C:\Users\Jerry\anaconda3\Lib\site-packages\numpy\__init__.py:143: 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\Jerry\anaconda3\Lib\site-packages\numpy\core\__init__.py", line 22, in <module>
        from . import multiarray
      File "C:\Users\Jerry\anaconda3\Lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
        from . import overrides
      File "C:\Users\Jerry\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 "D:\Work\dev2qa.com-example-code\PythonExampleProject\com\dev2qa\example\code_learner_dot_com_example\numpy_example.py", line 7, in <module>
        import numpy as np
      File "C:\Users\Jerry\anaconda3\Lib\site-packages\numpy\__init__.py", line 145, in <module>
        from . import core
      File "C:\Users\Jerry\anaconda3\Lib\site-packages\numpy\core\__init__.py", line 48, in <module>
        raise ImportError(msg)
    ImportError: 
    
    IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
    
    Importing the numpy C-extensions failed. This error can happen for
    many reasons, often due to issues with your setup or how NumPy was
    installed.
    
    We have compiled some common reasons and troubleshooting tips at:
    
        https://numpy.org/devdocs/user/troubleshooting-importerror.html
    
    Please note and check the following:
    
      * The Python version is: Python3.8 from "C:\Users\Jerry\anaconda3\python.exe"
      * The NumPy version is: "1.20.1"
    
    and make sure that they are the versions you expect.
    Please carefully study the documentation linked above for further help.
    
    Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
    

2. How To Fix The Undefined Variable From Import: Array Error.

  1. First, you should make sure you have installed the python Numpy package in your Anaconda virtual python environment ( you can refer to How To Install Python Package Numpy, Pandas, Scipy, Matplotlib On Windows, Mac, And Linux ).
  2. Then in the LiClipse left side PyDev Package Explorer panel, click the python project name —> your anaconda python interpreter icon —> External Libs —> Lib/site-packages, you should find the Numpy module under it.
  3. If you can not find the Numpy module there, you should use your anaconda virtual python environment ( which has installed the Numpy module ) as your LiClipse python interpreter ( you can refer to  How To Change Python Interpreter In Eclipse Pydev Project To Use Different Python Virtual Environment LibraryHow To Fix Eclipse Pydev Interpreter Not Found Issue).
  4. Finally, I find the below methods to fix this issue.
  5. Run the command pip uninstall numpy to uninstall the python NumPy module.
  6. Then run the command pip install numpy to install the latest NumPy version.
  7. After installation, my NumPy version is like below.
    (base) C:\Users\Jerry>pip show numpy
    Name: numpy
    Version: 1.21.4
    Summary: NumPy is the fundamental package for array computing with Python.
    Home-page: https://www.numpy.org
    Author: Travis E. Oliphant et al.
    Author-email: None
    License: BSD
    Location: c:\users\jerry\anaconda3\lib\site-packages
    Requires:
    Required-by: tifffile, tables, statsmodels, seaborn, scipy, scikit-learn, scikit-image, PyWavelets, pyerfa, patsy, pandas, numexpr, numba, mkl-random, mkl-fft, matplotlib, imageio, imagecodecs, h5py, Bottleneck, bokeh, bkcharts, astropy

3. How To Fix 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.

  1. Run the command pip uninstall mkl-service to uninstall the current installed mkl-service python module.
  2. Then run the command pip install mkl-service to install the latest version of the python mkl-service module.
  3. After installation, my mkl-service version is as below.
    (base) C:\Users\Jerry>pip show mkl-service
    Name: mkl-service
    Version: 2.4.0
    Summary: MKL Support Functions
    Home-page: https://github.com/IntelPython/mkl-service
    Author: Intel
    Author-email: None
    License: BSD
    Location: c:\users\jerry\anaconda3\lib\site-packages
    Requires: six, mkl
    Required-by:
  4. Restart the LiClipse IDE and then you can run the python script successfully.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.