A method is proposed for calculating the shear viscosity of a liquid from finite-size effects of self-diffusion coefficients in Molecular Dynamics simulations. This method uses the difference in the self-diffusivities, computed from at least two system sizes, and an analytic equation to calculate the shear viscosity. To enable the efficient use of this method, a set of guidelines is developed. The most efficient number of system sizes is two and the large system is at least four times the small system. The number of independent simulations for each system size should be assigned in such a way that 50%-70% of the total available computational resources are allocated to the large system. We verified the method for 250 binary and 26 ternary Lennard-Jones systems, pure water, and an ionic liquid ([Bmim][Tf2N]). The computed shear viscosities are in good agreement with viscosities obtained from equilibrium Molecular Dynamics simulations for all liquid systems far from the critical point. Our results indicate that the proposed method is suitable for multicomponent mixtures and highly viscous liquids. This may enable the systematic screening of the viscosities of ionic liquids and deep eutectic solvents.