Import Error when called from other than the NGSolve GUI

I just updated to NGS 6.2.2003 (Windows 10 machine with Anaconda python 3.7). I get the error below if I run this in jupyter or an IDE like Spyder, but not when executed from a python call from inside the NGSolve gui. I’d like to be able to run scripts in Jupyter. Any suggestions for how to fix this?

Thanks.

import netgen.gui
from ngsolve import *
from netgen.geom2d import unit_square
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-76ebde58f411> in <module>
      1 import netgen.gui
----> 2 from ngsolve import *
      3 from netgen.geom2d import unit_square

C:\Program Files\ngsolve-v6.2.2003\lib\site-packages\ngsolve\__init__.py in <module>
     11 """
     12 import netgen
---> 13 from .ngslib import __version__, ngstd, bla, la, fem, comp, solve
     14 
     15 from netgen import Redraw

ImportError: DLL load failed: The specified procedure could not be found.

Do you use the new anaconda installers?

I updated to the latest ngsolve package (2003) from within the Anaconda navigator. Would that have picked up the right components?

That depends. Have you had another ngsolve installed before? If yes you have to remove that one first. Then it should work.

Ok, I worked through the suggestions above and things seemed to be working. I started with the poisson example in Jupyter notebook. All cells seem to execute properly except the Draw(gfu) function. As I understand from the documentation this is supposed to show results in a popup window? In my case nothing happens. I did notice that even though the first cell (below) seems to execute fine, the following error shows up in the command prompt window. Is it possible they are related and any suggestions for resolving the error? I am using Python 3.7.7.

import netgen.gui
from ngsolve import *
from netgen.geom2d import unit_square
ERROR:tornado.application:Exception in callback functools.partial(<function Kernel.enter_eventloop.<locals>.advance_eventloop at 0x000001E799E55708>)
Traceback (most recent call last):
  File "c:\users\jon\appdata\local\programs\python\python37\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
    ret = callback()
  File "c:\users\jon\appdata\local\programs\python\python37\lib\site-packages\ipykernel\kernelbase.py", line 314, in advance_eventloop
    eventloop(self)
  File "c:\users\jon\appdata\local\programs\python\python37\lib\site-packages\ipykernel\eventloops.py", line 232, in loop_tk
    app.tk.createfilehandler(stream.getsockopt(zmq.FD), READABLE, notifier)
AttributeError: '_tkinter.tkapp' object has no attribute 'createfilehandler'

As explained in the documentation, this is a problem with recent ipykernel versions in Windows:
https://ngsolve.org/docu/latest/install/usejupyter.html

You have to downgrade your ipykernel:

pip install ipykernel==4.10.0

Best
Christopher

I am facing the same problem as jleman (ImportError: DLL load failed: The specified procedure could not be found.) and its the first time that I have downloaded ngsolve after reading instructions. Also, I have already downgraded my ipykernel to version 4.10.0. Now, what else should I do? Please reply asap

I had the same problem before. I uninstalled everything, then installed the newest version of ngsolve. It worked.

I made a fresh install of Miniconda3 py37 4.8.3, and installed with “conda install -c ngsolve ngsolve”

For some reason, this installed version 6.2.2004 (instead of 2007, which was just released today).

I cannot run any of the NGSolve examples in either Spyder or command line Python. I always get the error:

from ngsolve import *

File “C:\Miniconda3\lib\site-packages\ngsolve_init_.py”, line 13, in
from .ngslib import version, ngstd, bla, la, fem, comp, solve

ImportError: DLL load failed: The specified procedure could not be found.

There seem to be issues with dependency solving in conda recently, see

Make sure that netgen ist installed from channel ngsolve and not from conda-forge.
You can try either
conda update --all
or
conda remove netgen ngsolve
conda install -c ngsolve netgen
conda install -c ngsolve ngsolve

Another possibility is to use the ngsolve-nighlty package (due to another name it will not consider netgen in conda-forge as dependency).

Best,
Matthias

Thanks for the suggestion Matthiash, it worked for me!
Please note that NetGen got downgraded when I installed NGSolve:

C:\Miniconda3>conda install -c ngsolve netgen
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done

Package Plan

environment location: C:\Miniconda3

added / updated specs:
- netgen

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
ffmpeg-3.4.2               |       hf82bc7d_1        17.2 MB  conda-forge
netgen-6.2.2005            |           py37_5         4.2 MB  ngsolve
------------------------------------------------------------
                                       Total:        21.5 MB

The following NEW packages will be INSTALLED:

ffmpeg conda-forge/win-64::ffmpeg-3.4.2-hf82bc7d_1
netgen ngsolve/win-64::netgen-6.2.2005-py37_5

Proceed ([y]/n)? y

Downloading and Extracting Packages
ffmpeg-3.4.2 | 17.2 MB | ############################################################################ | 100%
netgen-6.2.2005 | 4.2 MB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

C:\Miniconda3>conda install -c ngsolve ngsolve
Collecting package metadata (current_repodata.json): done
Solving environment: done

Package Plan

environment location: C:\Miniconda3

added / updated specs:
- ngsolve

The following packages will be downloaded:

package                    |            build
---------------------------|-----------------
netgen-6.2.2004            |          py37_25         4.2 MB  ngsolve
------------------------------------------------------------
                                       Total:         4.2 MB

The following NEW packages will be INSTALLED:

ngsolve ngsolve/win-64::ngsolve-6.2.2004-py37_6

The following packages will be DOWNGRADED:

netgen 6.2.2005-py37_5 → 6.2.2004-py37_25

Proceed ([y]/n)? y

Downloading and Extracting Packages
netgen-6.2.2004 | 4.2 MB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

To make it short, it means that you lacked some “dependencies” for the libraries you wanted to use. This is a common problem when installing python packages, mainly in windows. Before trying to use any kind of library, first it is suggested to look up whether it needs another library in python “family”.

The solution is to provide the python interpreter with the path-to-your-module/library. The simplest solution is to append that python path to your sys.path list. In your notebook, first try:

import sys
sys.path.append(‘my/path/to/module/folder’)

This isn’t a permanent change in sys.path, because when you log out, your environment is reset, so any variables you may have set are lost.

The better (and more permanent) way to solve this is to set your PYTHONPATH, which provides the interpreter with additional directories look in for python packages/modules.

from BASH type: export PYTHONPATH=/path/to/new/folder:/another/path/…/ #each path must be separated by a colon