The partition function should assign to each possible field configuration $\Phi$ (or field history) in your quantum field theory a number $Z(\Phi)$. That is, it should be a function on the collection of fields configurations, and from that function you can derive lots of quantities in the field theory.
It can happen, however, that in order to come up with, or write down, the number $Z(\Phi)$, you need to make some auxiliary choices. Often these choices work only for certain fields, rather than for all fields at the same time. For instance, in a gauge theory with fermions you might need to choose a real number $\lambda$ which is not in the spectrum $\sigma(D_A)$ of the Dirac operator coupled to the gauge field $A$. In general, such a choice cannot be made for all gauge potentials $A$ simultaneously, and hence exists "only locally" on the collection of fields. Different local choices of auxiliary information will lead to different values of what you compute as $Z(\Phi)$, and it usually turns out that the transformation law between the values of $Z(\Phi)$ for different auxiliary choices is that of a section of a line bundle on the collection of fields.
What people normally want in gauge theory is for the partition function to be well-defined on the space $\mathcal{A}/\mathcal{G}$ of gauge potentials modulo gauge transformations. While any line bundle on $\mathcal{A}$ is trivialisable (since $\mathcal{A}$ is an affine space), this is not true on the quotient $\mathcal{A}/\mathcal{G}$. Let us say that our partition function can be understood as a section $Z$ of a line bundle $L \to \mathcal{A}/\mathcal{G}$. Then, any trivialisation of $L$ allows us to translate $Z$ into a function on $\mathcal{A}/\mathcal{G}$, and hence into an actual partition function. The QFT anomaly can hence be described as the obstruction to the existence of a trivialisation of $L$ -- this is a class in $H^2(\mathcal{A}/\mathcal{G};\mathbb{Z})$. Often this class can be computed, like in the case of the Dirac anomaly.
Some nice mathematical references, in my opinion, are https://arxiv.org/abs/hep-th/9907189, https://arxiv.org/abs/math-ph/0603031v1, and for a more conceptual perspective, https://arxiv.org/pdf/1212.1692.pdf.