FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
746 stars 179 forks source link

Cannot import library from dolfinx(Create 2D mesh) #2900

Closed OumPasuta00 closed 10 months ago

OumPasuta00 commented 10 months ago

How to reproduce the bug

Hello, I’m currently a student who’s a beginner in FEM at coding I want to create 2D mesh for solving PDEs in Jupyter notebook but I have a problem running the library as following;

!git clone https://github.com/FEniCS/dolfinx.git import dolfinx from dolfinx import mesh as _mesh ImportError: cannot import name 'mesh' from 'dolfinx' (unknown location) This happens every time when I import any libraries from dolfinx such as io, la, fem &etc.

,this error always happen too. from mpi4py import MPI domain = dolfinx.mesh.create_rectangle(comm=MPI.COMM_WORLD, points=((0, 0), (2, 1)), n=(32, 16)) AttributeError: module 'dolfinx' has no attribute 'mesh'

And this error from dolfinx.cpp.fem import transpose_dofmap
ModuleNotFoundError: No module named 'dolfinx.cpp.fem'

So I have 3 issues ImportError, AttributeError and ModuleNotFoundError even if I can import dolfinx but cannot use any libraries from dolfinx. Please give me some advice in details as a new beginner, Thank you.

Minimal Example (Python)

!git clone https://github.com/FEniCS/dolfinx.git
import dolfinx
from dolfinx import mesh as _mesh

Output (Python)

ImportError: cannot import name 'mesh' from 'dolfinx' (unknown location)

Version

main branch

DOLFINx git commit

!git clone https://github.com/FEniCS/dolfinx.git import dolfinx

Installation

I use Jupyter notebook on anaconda (window11)

Additional information

No response

adeebkor commented 10 months ago

How did you install dolfinx? By the way, this question is more suited on the fenics discourse page https://fenicsproject.discourse.group.

jorgensd commented 10 months ago

You should not run import of a Python module from a location where there is a folder with the same name. As @adeebkor says, you need to install the code as shown in: https://github.com/FEniCS/dolfinx#installation

OumPasuta00 commented 10 months ago

How did you install dolfinx? By the way, this question is more suited on the fenics discourse page https://fenicsproject.discourse.group.

i just use "!git clone https://github.com/FEniCS/dolfinx.git " and then "import dolfinx"

OumPasuta00 commented 10 months ago

You should not run import of a Python module from a location where there is a folder with the same name. As @adeebkor says, you need to install the code as shown in: https://github.com/FEniCS/dolfinx#installation

for the installation "C++ core" , "Python interface" and "Spack" what is the command line should i run on, on command prompt or any program??

OumPasuta00 commented 10 months ago

You should not run import of a Python module from a location where there is a folder with the same name. As @adeebkor says, you need to install the code as shown in: https://github.com/FEniCS/dolfinx#installation

Sorry but i dont understand this "Python module from a location where there is a folder with the same name" Could you describe more, thank you

adeebkor commented 10 months ago

As @jorgensd mentioned, you first need to install dolfinx using the command shown in: https://github.com/FEniCS/dolfinx#installation. There are couple of ways to do this but based on your OS (window11), the recommended way is to use docker.

jorgensd commented 10 months ago

How did you install dolfinx? By the way, this question is more suited on the fenics discourse page https://fenicsproject.discourse.group.

i just use "!git clone https://github.com/FEniCS/dolfinx.git " and then "import dolfinx"

DOLFINx is a C++/Python package. It has to be installed, by any of the means shown in the documentation. Say you are located at place in your file system, where you have two folders files and dolfinx. You should not create a script in this folder that calls import dolfinx, as it will try to import from the folder in this directory.

Please read the installation instructions, and any further issues with installation should be posted at https://fenicsproject.discourse.group/.