In this paper we give a simple proof that when the particle number is conserved , the Lagrangian of a barotropic perfect fluid is \mathcal { L } _ { m } = - \rho \left [ c ^ { 2 } + \int P ( \rho ) / \rho ^ { 2 } d \rho \right ] , where \rho is the rest mass density and P ( \rho ) is the pressure . To prove this result nor additional fields neither Lagrange multipliers are needed . Besides , the result is applicable to a wide range of theories of gravitation . The only assumptions used in the derivation are : 1 ) the matter part of the Lagrangian does not depend on the derivatives of the metric , and 2 ) the particle number of the fluid is conserved ( \nabla _ { \sigma } ( \rho u ^ { \sigma } ) = 0 ) .