A simple derivation is given of the quantum mechanical expression for the second virial coefficient in terms of the scattering phase shifts. The derivation does not require the introduction of a quantization volume and is based on the identity R(z)−R0(z) = R0(z)H1R(z), where R0(z) and R(z) are the resolvent operators corresponding to the unperturbed and total Hamiltonians H0 and H0 + H1 respectively. The derivation is valid in particular for a gas of excitons in a crystal for which the shape of the waves describing the relative motion of two excitons is not spherical, and, in general, varies with varying energy. The validity of the phase shift formula is demonstrated explicitly for this case by considering a quantization volume with a boundary the shape of which varies with the energy in such a way that for each energy the boundary is a surface of constant phase. The density of states prescribed by the phase shift formula is shown to result if the enclosed volume is required to be the same for all energies.