Reputation:
ModuleNotFoundError: No module named 'time.sleep'; 'time' is not a package
This is the error I get when I type import time.sleep as sleep
using 3.7.0a IDLE. Not sure about the as sleep
part, but the import time.sleep
seems to be broken or something like that. I tried the same thing with import time
as well, got the same result. Could someone please explain?
Edit: I was told that I should try 'import time' first and then 'time.sleep', but as >I said before:
I tried the same thing with 'import time' as well...
that does not work either. And another suggestion was that maybe I had >another file named time.py, and that it confused the programme. But as far as I >know (from a full search through my computer), I do not have another time.py >file that might be the cause. Any other suggestions please?
Upvotes: 0
Views: 4396
Reputation: 129
sleep is a method of time module, so first you need to import the module and then you can use methods of it, In your case:
>>> import time
>>> time.sleep
or
>>> from time import sleep
should work, But as you said import time
is also not working, So you need to make sure that there's no time.py file present in your directory (from where you're invoking the python shell)
Upvotes: 0
Reputation: 2827
You can do the following and it will work:
from time import sleep
The reason your import did not work is because time.sleep
is not a module. sleep
is a method (function). If you use import time
and then time.sleep()
it will work as well.
Upvotes: 2