An electric compressor that is compact and efficiently exchanges the heat arisen by its inverter. The compressor includes a housing, an electric motor, and a compression mechanism accommodated in the housing. The compression mechanism is driven by the electric motor to compress a refrigerant. The inverter is attached to the outer surface of the housing to drive the electric motor. The inverter includes a switching device having a heat radiating surface. A groove is formed in the outer surface of the housing. The switching device is inserted in the groove so that the heat radiating surface contacts the wall of the groove to efficiently exchange heat with the compressor housing.