Is internal energy a function of pressure?
Solution 1
For an ideal gas the internal energy only depends on the temperature of the gas. How the temperature relates to pressure is easily seen in the ideal gas law $$PV=NkT$$ So I suppose one could make the argument that the internal energy for the ideal gas depends on the quantity $$\frac{PV}{Nk}$$ and it's up to you how you want to explain the dependency. The problem with this though is that, depending on the process, these variables are constrained to evolve in certain ways.
Indeed, for your compression example, how you are compressing the gas matters. I will cover some typical examples:
If the gas is compressed in such a way so that its pressure is inversely proportional to it's volume, then by the ideal gas law the temperature remains constant. It turns out that in this case the heat that leaves the gas is exactly balanced by the work you do on it. The internal energy does not change.
If the gas is compressed in such a way so that its pressure remains constant, then by the ideal gas law the temperature drops in proportion to the volume. In this case more energy leaves the system as heat than what you put in as work. The internal energy decreases.
If the gas is compressed in such a way so that no heat enters or leaves the system, then all the work you do goes into increasing the internal energy, and hence the temperature of the gas. This process is probably what you had in mind. Here the pressure and volume both change, but the pressure increases in a larger proportion than the volume decreases$^*$. Therefore, by the ideal gas law the temperature increases.
$^*$ In fact, for this process the value $PV^\gamma$ is constant where $\gamma>1$. So, if $V$ decreases by a factor $x>1$, then $P$ must increase by a factor of $x^{\gamma}$. This means that $PV$, and hence $T$, must increase by a factor of $x^{\gamma1}>1$.
Solution 2
As @Asron Stevens has already pointed out the answers to your questions really depend on the thermodynamic process involved as well as the type of gas (ideal or real). For example he has shown you that, for an ideal gas, you can have an increase in pressure with no change in temperature or internal energy (isothermal compression).
When you say you read “internal energy is a function of temperature only”, that is correct for ideal gases because there are no intermolecular forces and therefore their internal energy is considered to be all kinetic energy. However it is not necessarily correct for real gases where intermolecular (van der Waal) forces are involved and therefore internal energy is the sum of its internal kinetic and potential energy.
Moving away from gases to solids and liquids, you can have an increase or decrease in the total internal energy without a change in temperature during isothermal phase changes. Phase changes are generally associated with changes in the potential energy component of the internal energy of substances.
Hope this helps.
Solution 3
The important thing to remember is that U is a function of state (a property of the material) independent of any process. Between two thermodynamics equilibrium states, the change in U is independent of the specific process path that was used to transition the system between these two states. There are an infinite number of paths that can go between the two states, and Q and W can vary between these paths, but the change in U will be the same for all of them. So one might as well use a reversible path for which dU = TdS  PdV. This leads to the relationship between dU and dT and dP that I wrote down in a comment in @BobD's answer.
For an ideal gas, U and H are functions only of T, but for real gases, liquids, and solids, they are also functions of P (and/or V). This is because the ideal gas behavior applies to real gases in the limit of low pressures, where the molecules are far apart (and don't interact energetically to a significant extent). In real gases, the pressures/densities are higher, and the molecules do interact significantly, resulting in potential energy interactions and thus effects on internal energy.
Related videos on Youtube
Swaroop Joshi
Updated on August 01, 2022Comments

Swaroop Joshi 10 months
I read that internal energy is a function of temperature only and not pressure. But say, we compress a volume of gas. Won't the particles start moving more quickly? Meaning an increase in their internal energy.
Is this an increase in the internal energy due to pressure? Or an increase in temperature due to pressure which in turn increases the energy? How do I see this?

Chet Miller over 3 yearsFor a real gas, liquid, or solid, $$dU=C_vdT\left[PT\left(\frac{\partial P}{\partial T}\right)_V\right]\left(\frac{\partial V}{\partial P}\right)_TdP$$. For an ideal gas, the coefficient of dP is zero.

Bob D over 3 years@ChetMiller Hi Chet. Thanks. Can you direct me to a derivation of this equation? Also, for a liquid or solid $C_v$ is just $C$.

Chet Miller over 3 yearsWe've discussed the derivation of dU as a function of dT and dV in other threads. It is in all the books. I used the chain rule to modify the equation so that it is in terms of dT and dP. For liquids and solids, Cv is just C(T) only for incompressible liquids and solids.