25

I've tried pip install time and sudo -H pip install time, but I keep getting the error:

Could not find a version that satisfies the requirement time (from versions: ) No matching distribution found for time

I'm working in PyCharm, but what really doesn't make sense is that I can import time in the Python Console but not in my actual code.

franklinsijo
  • 17,784
  • 4
  • 45
  • 63

13 Answers13

31

The time module is part of Python's standard library. It's installed along with the rest of Python, and you don't need to (nor can you!) install it with pip.

I can import time in the Python Console

Yes, because it's already installed.

but not in my actual code

I don't believe you. Show us the exact error message you get when you try.

jwodder
  • 54,758
  • 12
  • 108
  • 124
9

I think this is a PyCharm bug. I am using the time module with PyCharm and it complains that 'time' is an unresolved reference, even when I use

import time

at the beginning of my file. However, there is no run-time error when I execute my program, even though PyCharm does not recognise time as a valid module.

snibbets
  • 1,095
  • 10
  • 11
2

Try using time.sleep(secs) that should work fine.

1

just use it . time library default installed in python for use : add to code :

import time

and use for example :

time.sleep(20) #20 second
mamal
  • 1,791
  • 20
  • 14
1

You cannot create an object with the name "time" because it will conflict with the "time" module.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
1

If you have already imported time up top import time and time is shown as an unresolved reference, then probably either an existing variable of time exists or time is imported outside of the function -- in both cases, you should be able to call time with a different name.

import time as tme

def_hi():
    print(tme.time())
Adam Burke
  • 724
  • 1
  • 7
  • 21
1

Even if import time is in grey, it works ! You just gotta put time.init() or something like that right after it

n4321d
  • 1,059
  • 2
  • 12
  • 31
Bobigazi
  • 11
  • 2
0

I have also got the error, while referring the time on the 'requirements.txt' and pushing app to cloud foundry.

So the errors is expected. So, its possible on other scenarios also. I just removed the time from the 'requirements.txt' before push my app to make it work.!

MohanBabu
  • 407
  • 5
  • 14
0

time is pre-installed because when I import time "import time" everything goes well

moe_
  • 219
  • 2
  • 3
  • 15
0

I think I had the same problem, I think it's because one variable was called time...

0

I experienced this bug too with pycharm. If I import time outside of the function then I won't be able to call it inside the function.

import time
def poop():
    print(time.time()) # Undefined varr time

I was able to get around it by importing as a different name

import time as tm
def poop():
    print(tm.time()) # Works

If you want to be inefficient you could do

def poop():
    import time
    print(time.time()) # Works

Hope this helps

0

It happened to me, the only thing that happened to me was that a variable was given the name "time", that's why the time module didn't work, I didn't know this, so after searching, I was able to change the name of that variable and To end the torment I was trapped in.

-1

You should first import the library. So add a statement like: import