Windows系统下通过Anaconda Prompt安装Fenics(Dolfin依赖)报错求助
Hey there, I’ve dealt with this exact frustration before—FEniCS (and its core component DOLFIN) can be tricky to set up natively on Windows via Anaconda because some of its low-level dependencies (like PETSc or MPI) don’t play nicely with Windows’ environment. Let’s go through the most reliable fixes:
1. Use WSL2 (Recommended for Stability)
FEniCS is built primarily for Linux, so running it via Windows Subsystem for Linux 2 gives you the smoothest experience:
- Enable WSL2 on your Windows machine (search "Turn Windows features on or off" and check "Windows Subsystem for Linux" and "Virtual Machine Platform").
- Install Ubuntu from the Microsoft Store, then launch it to set up your Linux user account.
- Inside the Ubuntu terminal, install Anaconda (or Miniconda) just like you would on Linux.
- Run your original conda command—it should work without issues now:
conda create -n fenicsproject -c conda-forge fenics - Activate the environment and import
dolfinin Python to confirm it works.
2. Use Docker (Great for Isolated Environments)
If you don’t want to set up WSL, Docker wraps FEniCS in a pre-configured container:
- Install Docker Desktop for Windows and enable WSL2 integration in Docker settings.
- Open PowerShell or Command Prompt and pull the official FEniCS image:
docker pull fenics/fenics:latest - Run a container with access to your local files (replace
C:\your\work\directorywith your actual project folder):docker run -ti -v C:\your\work\directory:/home/fenics/shared fenics/fenics:latest - Inside the container, you can use Python and
dolfinimmediately—no dependency headaches.
3. Native Windows Conda Workaround (Hit-or-Miss)
If you really need to run it natively on Windows, try pinning an older FEniCS version that had better Windows support, and force conda to prioritize conda-forge:
- First, update your conda channels to make conda-forge the top priority:
conda config --add channels conda-forge conda config --set channel_priority strict - Then create the environment with a specific older version:
conda create -n fenicsproject fenics=2019.1.0
Note: This might still fail due to missing Windows-specific dependencies, so only use this if WSL/Docker aren’t options.
The root issue with your original command is that newer FEniCS versions have dependencies that aren’t fully maintained for Windows on conda-forge. WSL or Docker will save you a lot of troubleshooting time!
内容的提问来源于stack exchange,提问作者J.A

