Praise and encourage effort. Help your students develop a “growth mindset” by praising their effort and diligence (e.g., "I'm so impressed with the hard work you put into this!") instead of emphasizing that they are smart or talented (immutable characteristics). Having a growth mindset is associated with persistence and “grit”.
Work it into your course materials. Integrate language into course materials that provides encouragement along the way (e.g., "This next task is challenging, so make sure you allocate enough time to complete it, including time you might need to seek help.") and positive reinforcement for completing tasks (e.g., "Congratulations on completing that difficult assignment!").
Make it okay to make a mistake. Let students know that we all make mistakes, get stuck, and have to redo things. Help them uncover their mistakes and encourage them to persist (e.g., "I see what you're doing and that's a typical mistake students make. Try it this way and see what happens.").