Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Gracie Jensen
Gracie Jensen
1,942 Points

module suddenly not found

I have had this happen several times using several different platforms -- I'll have imported a module into my current script and it will run just fine over and over, but then randomly after doing something that has no effect on importing the module (i.e. adding a function that literally just used copy-paste code from another function in the main file), I'll run the program and get a module not found error for a module it's been using up to that point with no problem. The most recent instance has been in importing dateutil and using it with no issues until suddenly it's no longer found. I even erased the code I wrote in between it working and it not working in case it somehow didn't like it but the script just won't run.

If this is relevant, I am working on a MacBook Air (don't come @ me), and have experienced this using both Thonny and PyCharm.

1 Answer

Rachel Johnson
Rachel Johnson
Treehouse Teacher

Hey Gracie Jensen , thanks for sharing your question!

It's definitely a little tricky to pinpoint what's happening exactly as I can't see what it looks like. However, it may have something to do with your virtual environment. The example you provided, dateutil is a third-party package, something that you would have to install into a virtual environment. that is running your script. That, plus the fact that you're getting an ModuleNotFound Error, makes me believe that you may have exited the virtual environment at some point.

Since dateutil should be installed in a virtual environment, exiting the environment would naturally mean that the module cannot be found. Make sure you are running your script in the virtual environment. The name of the virtual environment should be in brackets before the path and blinking cursor.


I hope that helps!