I am trying to install NGSolve from source and followed the instructions as mentioned on the website. I get no errors when doing make and make install. However, when trying to import the compiled library in Python, I get the following error:
{
"name": "ModuleNotFoundError",
"message": "No module named 'pyngcore.pyngcore'",
"stack": "---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
File /scratch/users/wtonnon/VisualStudioProjects/ngsuite/ngsolve-src/comp/test_wouter/test2.py:10
7 sys.path.insert(0, ngsolve_install_path)
9 # Import ngsolve and print its file location
---> 10 import ngsolve
11 print(f\"ngsolve module imported from: {ngsolve.__file__}\")
13 # Continue with the rest of your script
File ~/VisualStudioProjects/ngsuite/ngsolve-install/lib64/python3.11/site-packages/ngsolve/__init__.py:17
13 import os, sys
15 from . import config
---> 17 import netgen
19 if config.is_python_package and sys.platform.startswith('win'):
20 netgen_dir = os.path.dirname(netgen.__file__)
File ~/VisualStudioProjects/ngsuite/ngsolve-install/lib64/python3.11/site-packages/netgen/__init__.py:98
95 del sys
96 del os
---> 98 from pyngcore import Timer
99 from . import libngpy
101 from netgen.libngpy._meshing import _Redraw
File ~/VisualStudioProjects/ngsuite/ngsolve-install/lib64/python3.11/site-packages/pyngcore/__init__.py:1
----> 1 from .pyngcore import *
ModuleNotFoundError: No module named 'pyngcore.pyngcore'"
}
In ngsolve-install/lib64/python3.11/site-packages, there is a folder pyngcore. However, this folder only contains __init__.py, __pycache__, and pyngcore.cpython-36m-x86_64-linux-gnu.so.
In comparison, the folder corresponding to the pip install version of pyngcore has the following: __init__.py, __init__.pyi, __pycache__, pyngcore.cpython-311-x86_64-linux-gnu.so, and pyngcore.pyi. Somehow, it seems that two of these files are missing in my installation from source. Is there a setting in the CMake that can change this?
-- Build Netgen from git submodule
Configure Netgen from submodule...
Checking for write permissions in install directory...
-- Found Python3: /usr/include/python3.11 (found version "3.11.9") found components: Development.Module
-- Found Python3: /usr/bin/python3.11 (found version "3.11.9") found components: Interpreter Development.Embed
-- Found Python3: /usr/bin/python3.11 (found version "3.11.9") found components: Interpreter
Checking for write permissions in install directory...
-- Found Pybind11: /scratch/users/wtonnon/VisualStudioProjects/ngsuite/ngsolve-src/external_dependencies/netgen/external_dependencies/pybind11/include
-- Found Python3: /usr/bin/python3.11 (found version "3.11.9") found components: Interpreter Development.Module
-- Found Python3: /usr/bin/python3.11 (found version "3.11.9") found components: Interpreter Development.Embed
-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /scratch/users/wtonnon/VisualStudioProjects/ngsuite/ngsolve-build/netgen
grep: /etc/lsb-release: No such file or directory
-- Configuring done (1.0s)
-- Generating done (0.0s)
-- Build files have been written to: /scratch/users/wtonnon/VisualStudioProjects/ngsuite/ngsolve-build
This seems to suggest that the library is being compiled against usr/bin/python3.11. I tried running my python code with Python3.6 as well, but I get the same error, unfortunately.
It seems you have some mixup where netgen finds the correct 3.11 python but pybind or so the 3.6…
try building with make VERBOSE=1 and look in the include/link paths if there is something off while building pyngcore.
Thank you for the hint, Christopher. I ended up passing the argument
-DPYTHON_EXECUTABLE=/usr/bin/python3
to cmake when initializing the build folder for NGSolve. According to the pybind11 documentation, this should force the use of this specific version of python. Indeed, the shared library is now called pyngcore.cpython-311-x86_64-linux-gnu.so, which seems to indicate that the right python version is now being used by pybind11. When I run the python script, the previous error does not appear anymore!
However, as in classical programming fashion, we get another error:
terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
Aborted (core dumped)
This occurs during the import of NGSolve. Any clue what this could be about? Probably it is still related to the installation somehow.