I need some help with installing the fenics Python package inside Slicer. I tried using pip_install('fenics') in the latest Slicer preview (4.11.0-2020-06-30 r29196 / 07bc921):
Python 3.6.7 (default, Jul 1 2020, 03:07:22)
[GCC 5.3.1 20160406 (Red Hat 5.3.1-6)] on linux2
>>> pip_install('fenics')
Collecting fenics
Using cached fenics-2019.1.0-py3-none-any.whl (1.5 kB)
Collecting fenics-ffc<2019.2,>=2019.1.0
Using cached fenics_ffc-2019.1.0.post0-py3-none-any.whl (362 kB)
Collecting fenics-dijitso<2019.2,>=2019.1.0
Using cached fenics_dijitso-2019.1.0-py3-none-any.whl (46 kB)
Collecting fenics-ufl<2019.2,>=2019.1.0
Using cached fenics_ufl-2019.1.0-py3-none-any.whl (282 kB)
Collecting fenics-fiat<2019.2,>=2019.1.0
Using cached fenics_fiat-2019.1.0-py3-none-any.whl (112 kB)
Requirement already satisfied: numpy in ./Slicer-4.11.0-2020-06-30-linux-amd64/lib/Python/lib/python3.6/site-packages (from fenics-ffc<2019.2,>=2019.1.0->fenics) (1.18.1)
Collecting sympy
Using cached sympy-1.6-py3-none-any.whl (5.8 MB)
Processing /home/ben/.cache/pip/wheels/63/9d/8e/37c3f6506ed3f152733a699e92d8e0c9f5e5f01dea262f80ad/mpmath-1.1.0-cp36-none-any.whl
Installing collected packages: fenics-dijitso, fenics-ufl, mpmath, sympy, fenics-fiat, fenics-ffc, fenics
WARNING: The script dijitso is installed in '/opt/slicer/Slicer-4.11.0-2020-06-30-linux-amd64/lib/Python/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script isympy is installed in '/opt/slicer/Slicer-4.11.0-2020-06-30-linux-amd64/lib/Python/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts ffc and ffc-3 are installed in '/opt/slicer/Slicer-4.11.0-2020-06-30-linux-amd64/lib/Python/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed fenics-2019.1.0 fenics-dijitso-2019.1.0 fenics-ffc-2019.1.0.post0 fenics-fiat-2019.1.0 fenics-ufl-2019.1.0 mpmath-1.1.0 sympy-1.6
WARNING: You are using pip version 20.1; however, version 20.1.1 is available.
You should consider upgrading via the '/opt/slicer/Slicer-4.11.0-2020-06-30-linux-amd64/bin/./python-real -m pip install --upgrade pip' command.
>>> import dolfin
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'dolfin'
>>> import fenics
Traceback (most recent call last):
File "<console>", line 1, in <module>
ModuleNotFoundError: No module named 'fenics'
>>> import ffc
>>> import dijitso
It appears that the installation is successful, but I cannot import the fenics or dolfin modules (although the related ffc and dijitso modules can be loaded).
I am using Ubuntu 18.04 and have FEniCS installed using PPA. In other words the non-Python components are available on my system path.
If you have a fenics folder in your lib/Python/Lib folder and it has a __init__.py file then the module should be found. You can edit the init file or other Python files to add logs to figure out where things break down.
Hi @lassoan, that is the extension that I developed I am trying to extend it for a different problem and also to simplify the installation. I have lost my previous development environment and it was quite difficult to install back then. I was hoping there may be a better way to install the Python modules. Last time I did it like this:
However, I have now installed FEniCS binaries instead of from source. I would like to just install the Python modules inside Slicer so I can import fenics or dolfin inside my extension module.
Thanks, I will try that. What is the best/recommended way to run pip to install/uninstall packages in Slicer? I have looked on the forum, wiki, documentation and there appear to be a few different ways to run pip. Do you have a link to the most up to date documentation for this?
Currently I am using this: https://www.slicer.org/wiki/Documentation/Nightly/Developers/FAQ/Python_Scripting#How_to_run_pip_.3F
Step 3 was suggested by @jcfr when I was developing Slicer FEniCS in Boston. Maybe it would be worthwhile to include these headers within the Slicer distribution. It is the only complicated step in the installation process here.
Hi Andras,
I have fenics in the 3d slicer. when I use interpreter I can import the fenics
but how can i import from within a module it says
Traceback (most recent call last):
File “”, line 1, in
File “/home/saima/Downloads/Slicer-4.11.20200930-linux-amd64/lib/Python/lib/python3.6/imp.py”, line 170, in load_source
module = _exec(spec, sys.modules[name])
File “”, line 618, in _exec
File “”, line 674, in exec_module
File “”, line 781, in get_code
File “”, line 741, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/home/saima/Downloads/Slicer-4.11.20200930-linux-amd64/VoxelizeMesh/crwateMesh/crwateMesh.py”, line 317
def process(self, inputVolume, outputVolume, imageThreshold, invert=False, showResult=True):
^
SyntaxError: import * only allowed at module level
from fenics import * is not allowed how can I fix it?