Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.3.5 time module missing

When I try to import time I get : No module named time

I have tried other time modules(datetime and timeit) and they work fine. I decided to check my installation and I can't find time.py anywhere. I checked the Lib, Scripts, libs and include folders, but can't find it anywhere.

Anyone know what I can do to fix this? Maybe download the .py and put it in Lib myself?

I am using Python 3.3.5 with PyCharm IDE. Only extra scripts I've installed is EasyInstall and PRAW.

like image 828
Vinc Avatar asked Jan 14 '15 07:01

Vinc


People also ask

How do I get the time in Python 3?

Python 3 - time time() Method The method time() returns the time as a floating point number expressed in seconds since the epoch, in UTC.

How do I download a time module from Python?

The time module comes with Python's standard utility module, so there is no need to install it externally. We can simply import it using the import statement.

Does Python still need __ init __?

The __init__.py files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as string , unintentionally hiding valid modules that occur later on the module search path.

Why are my Python modules not working?

This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.


2 Answers

The import does work. When PyCharm said No module named time, I assumed I would get a compiler error and started trying to fix it.

However when I eventually just ran the code it worked fine. I expect PyCharm doesn't detect the time module as it's a dll and not a py as noted by Martijn in the comments. This is on PyCharm Community Edition 4.0.4.

like image 139
Vinc Avatar answered Oct 22 '22 08:10

Vinc


I tried playing with virtualenv and a host of other things, but I eventually went to Preferences -> Build, Execution, Deployment -> Console -> Python Console, and in the "starting script" box, I added two lines:

sys.builtin_module_names.append('sys')
sys.builtin_module_names.append('time')

This got rid of errors I had with both sys and time. Once I did that, I even get autocomplete for both of those modules... weird.

like image 2
ZachM Avatar answered Oct 22 '22 08:10

ZachM