A work machine comprising: a plurality of hydraulic actuators (7a to 7c, 10c); a plurality of variable displacement hydraulic pumps (2a to 2f) to drive the hydraulic actuators (7a to 7c, 10c); a plurality of switching valves connected between the hydraulic actuators (7a to 7c, 10c) and the hydraulic pumps (2a to 2f); an operation lever to operate the hydraulic actuators (7a to 7c, 10c); and a controller to control the hydraulic pumps (2a to 2f) and the switching valves, at least two of the hydraulic pumps (2a to 2f) connected in a closed loop to any one of the hydraulic actuators (7a to 7c, 10c) through the switching valves, characterized in that: the controller includes a priority order calculating circuit which calculates allocation of the hydraulic pumps (2a to 2f) to the hydraulic actuators (7a to 7c, 10c) according to operation of the operation lever and a priority order map predetermining priority connection relationships between the hydraulic pumps (2a to 2f) and the hydraulic actuators (7a to 7c, 10c); and in a state where given hydraulic pumps among the hydraulic pumps (2a to 2f) are allocated to given hydraulic actuators (7a to 7c, 10c) among the hydraulic actuators (7a to 7c, 10c), when the operation lever provides other hydraulic actuators (7a to 7c, 10c) which are different from the given hydraulic actuators (7a to 7c, 10c) with driving commands, the priority order calculating circuit allocates the hydraulic pumps (2a to 2f) to the other hydraulic actuators (7a to 7c, 10c) in a higher order of a predetermined priority among the hydraulic pumps (2a to 2f) which are not allocated to the given hydraulic actuators (7a to 7c, 10c); and in a state where a hydraulic pump (2a to 2f) having a higher priority to the other hydraulic actuators (7a to 7c, 10c) than the hydraulic pumps (2a to 2f) which are allocated to the other hydraulic actuators (7a to 7c, 10c) exists among the hydraulic pumps (2a to 2f) which are allocated to the given hydraulic actuators (7a to 7c, 10c), when the target number of the given hydraulic pumps (2a to 2f) to be allocated to the given hydraulic actuators (7a to 7c, 10c) decreases in accordance with a decrease in a manipulated variable of the operation lever and the hydraulic pump (2a to 2f) having the higher priority to the other hydraulic actuators (7a to 7c, 10c) than the hydraulic pumps (2a to 2f) allocated to the other hydraulic actuators (7a to 7c, 10c) is unallocated to the given hydraulic actuators (7a to 7c, 10c), the priority order calculating circuit maintains allocation of the hydraulic pumps (2a to 2f) allocated to the other hydraulic actuators (7a to 7c, 10c) while it reduces the number of the given hydraulic pumps (2a to 2f) allocated to the given hydraulic actuator (7a to 7c, 10c). a plurality of hydraulic actuators (7a to 7c, 10c); a plurality of variable displacement hydraulic pumps (2a to 2f) to drive the hydraulic actuators (7a to 7c, 10c); a plurality of switching valves connected between the hydraulic actuators (7a to 7c, 10c) and the hydraulic pumps (2a to 2f); an operation lever to operate the hydraulic actuators (7a to 7c, 10c); and a controller to control the hydraulic pumps (2a to 2f) and the switching valves, at least two of the hydraulic pumps (2a to 2f) connected in a closed loop to any one of the hydraulic actuators (7a to 7c, 10c) through the switching valves, the controller includes a priority order calculating circuit which calculates allocation of the hydraulic pumps (2a to 2f) to the hydraulic actuators (7a to 7c, 10c) according to operation of the operation lever and a priority order map predetermining priority connection relationships between the hydraulic pumps (2a to 2f) and the hydraulic actuators (7a to 7c, 10c); and in a state where given hydraulic pumps among the hydraulic pumps (2a to 2f) are allocated to given hydraulic actuators (7a to 7c, 10c) among the hydraulic actuators (7a to 7c, 10c), when the operation lever provides other hydraulic actuators (7a to 7c, 10c) which are different from the given hydraulic actuators (7a to 7c, 10c) with driving commands, the priority order calculating circuit allocates the hydraulic pumps (2a to 2f) to the other hydraulic actuators (7a to 7c, 10c) in a higher order of a predetermined priority among the hydraulic pumps (2a to 2f) which are not allocated to the given hydraulic actuators (7a to 7c, 10c); and in a state where a hydraulic pump (2a to 2f) having a higher priority to the other hydraulic actuators (7a to 7c, 10c) than the hydraulic pumps (2a to 2f) which are allocated to the other hydraulic actuators (7a to 7c, 10c) exists among the hydraulic pumps (2a to 2f) which are allocated to the given hydraulic actuators (7a to 7c, 10c), when the target number of the given hydraulic pumps (2a to 2f) to be allocated to the given hydraulic actuators (7a to 7c, 10c) decreases in accordance with a decrease in a manipulated variable of the operation lever and the hydraulic pump (2a to 2f) having the higher priority to the other hydraulic actuators (7a to 7c, 10c) than the hydraulic pumps (2a to 2f) allocated to the other hydraulic actuators (7a to 7c, 10c) is unallocated to the given hydraulic actuators (7a to 7c, 10c), the priority order calculating circuit maintains allocation of the hydraulic pumps (2a to 2f) allocated to the other hydraulic actuators (7a to 7c, 10c) while it reduces the number of the given hydraulic pumps (2a to 2f) allocated to the given hydraulic actuator (7a to 7c, 10c).