For fluids at supercritical pressure, the phase change from liquid to gas does not exist. Meanwhile, the fluid properties change drastically in a narrow temperature range. With supercritical fluid as working fluid in a heated pipe, heat-transfer deterioration and recovery have been observed, which corresponds to the turbulent flow relaminarization and recovery. Direct numerical simulation (DNS) of supercritical carbon dioxide flow in a heated vertical circular pipe is developed with the open-source code OpenFOAM in this study. Forced-convection and mixed-convection cases including upward and downward flow have been considered in the simulation. In the forced convection, flow turbulence is attenuated due to acceleration from thermal expansion, which leads to a peak of the wall temperature. However, buoyancy shows a stronger impact on the flow. In the upward flow, the average streamwise velocity distribution turns into an M-shaped profile because of the external effect of buoyancy. Besides that, negative buoyancy production caused by the density variation reduces the Reynolds shear stress to almost zero, which means that the flow is relaminarized. Further downstream, turbulence is recovered. This behavior of flow turbulence is confirmed by visualization of turbulent streaks and vortex structures.