diff --git a/wrappers/gmshpy/gmshMesh.i b/wrappers/gmshpy/gmshMesh.i
index c48c77ac35b5c85ece9d214addd1dc597cd049a8..9fafb67a5dcf101a845d2a02ee2483d8b82bd356 100644
--- a/wrappers/gmshpy/gmshMesh.i
+++ b/wrappers/gmshpy/gmshMesh.i
@@ -4,17 +4,20 @@
 
 %{
   #include "GmshConfig.h"
-
+#if defined(HAVE_MESH)
   #include "Generator.h"
   #include "highOrderTools.h"
   #include "meshGFaceLloyd.h"
   #include "meshGFaceOptimize.h"
   #include "meshPartitionOptions.h"
   #include "Levy3D.h"
+#if defined(HAVE_METIS) || defined(HAVE_CHACO)
   #include "meshPartition.h"
+#endif
   #include "meshMetric.h"
   #include "Field.h"
   #include "CenterlineField.h"
+#endif
 %}
 
 %include std_vector.i
@@ -23,13 +26,17 @@ namespace std {
 }
 
 %include "GmshConfig.h"
+#if defined(HAVE_MESH)
 %include "Generator.h"
 %include "highOrderTools.h"
 %include "meshGFaceLloyd.h"
 %include "meshGFaceOptimize.h"
 %include "meshPartitionOptions.h"
 %include "Levy3D.h"
+#if defined(HAVE_METIS) || defined(HAVE_CHACO)
 %include "meshPartition.h"
+#endif
 %include "meshMetric.h"
 %include "Field.h"
 %include "CenterlineField.h"
+#endif
diff --git a/wrappers/gmshpy/gmshPost.i b/wrappers/gmshpy/gmshPost.i
index db5e70c9d0378e8dae079b17dd0953665f7d1650..82affcc12790214f97842af77d927f8b2599eceb 100644
--- a/wrappers/gmshpy/gmshPost.i
+++ b/wrappers/gmshpy/gmshPost.i
@@ -6,16 +6,18 @@
 %{
   #include "GmshConfig.h"
   #include "fullMatrix.h"
+#if defined(HAVE_POST)
   #include "PView.h"
   #include "PViewFactory.h"
   #include "PViewData.h"
+#endif
 %}
 
 %include "GmshConfig.h"
+#if defined(HAVE_POST)
 %include "PView.h"
-
 %include "PViewFactory.h"
-
 %apply double &OUTPUT { double &val}
 %include "PViewData.h"
+#endif
 
diff --git a/wrappers/gmshpy/gmshSolver.i b/wrappers/gmshpy/gmshSolver.i
index 244f7909e24c7c8ee657b0200df88c444d9a7540..0e0a917b99a950483d94e6f1d1bafa0d1bc57d0d 100644
--- a/wrappers/gmshpy/gmshSolver.i
+++ b/wrappers/gmshpy/gmshSolver.i
@@ -7,16 +7,18 @@
 
 %{
   #include "GmshConfig.h"
+#if defined(HAVE_SOLVER)
   #include "dofManager.h"
   #include "elasticitySolver.h"
   #include "linearSystem.h"
   #include "linearSystemCSR.h"
   #include "linearSystemFull.h"
   #include "linearSystemPETSc.h"
+#endif
 %}
 
 %include "GmshConfig.h"
-
+#if defined(HAVE_SOLVER)
 %include "dofManager.h"
 %template(dofManagerDouble) dofManager<double>;
 %include "elasticitySolver.h"
@@ -28,7 +30,8 @@
 %template(linearSystemTAUCSDouble) linearSystemCSRTaucs<double>;
 %include "linearSystemFull.h"
 %template(linearSystemFullDouble) linearSystemFull<double> ;
-#ifdef HAVE_PETSC
+#if defined(HAVE_PETSC)
 %include "linearSystemPETSc.h"
 %template(linearSystemPETScDouble) linearSystemPETSc<double>;
 #endif
+#endif