Foros del Web » Programando para Internet » Python »

[SOLUCIONADO] Problema libreria time, trheading

Estas en el tema de Problema libreria time, trheading en el foro de Python en Foros del Web. Buenas tengo este c'odigo en python: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Python: Ver original from time from threading import Thread   def myfunc ( i ) : ...
  #1 (permalink)  
Antiguo 03/04/2013, 06:04
 
Fecha de Ingreso: marzo-2013
Mensajes: 19
Antigüedad: 11 años, 1 mes
Puntos: 0
Problema libreria time, trheading

Buenas tengo este c'odigo en python:

Código Python:
Ver original
  1. from time
  2. from threading import Thread
  3.  
  4. def myfunc(i):
  5.     print "sleeping 5 sec from thread %d" % i
  6.     time.sleep(5)
  7.     print "finished sleeping from thread %d" % i
  8.  
  9. for i in range(10):
  10.     t = Thread(target=myfunc, args=(i,))
  11.     t.start()
pero me devuelve este error:
Código:
Traceback (most recent call last):
  File "./time.py", line 16, in <module>
    import time 

   from threading import Thread
  File "/usr/lib64/python2.7/threading.py", line 13, in <module>
    from time import time as _time, sleep as _sleep
ImportError: cannot import name sleep
Creo que me falta la libreria, como ago para instalarla?? he provado pip pero no lo consigo...

Gracias!!

Última edición por razpeitia; 03/04/2013 a las 09:48
  #2 (permalink)  
Antiguo 03/04/2013, 07:01
 
Fecha de Ingreso: febrero-2011
Mensajes: 54
Antigüedad: 13 años, 2 meses
Puntos: 18
Respuesta: Problema libreria time, trheading

Es esto:

Código Python:
Ver original
  1. import time
  2. from threading import Thread
  3.  
  4. def myfunc(i):
  5.     print "sleeping 5 sec from thread %d" % i
  6.     time.sleep(5)
  7.     print "finished sleeping from thread %d" % i
  8.    
  9. for i in range(10):
  10.     t = Thread(target = myfunc(i))
  11.     t.start()
  #3 (permalink)  
Antiguo 03/04/2013, 09:51
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Problema libreria time, trheading

Como ya te pusieron en el código, de arriba. La primera linea de código es import time no from time.
  #4 (permalink)  
Antiguo 03/04/2013, 10:25
 
Fecha de Ingreso: marzo-2013
Mensajes: 19
Antigüedad: 11 años, 1 mes
Puntos: 0
Respuesta: Problema libreria time, trheading

Perdonar, he echo el copiar/pegar mal, ya lo tenia como me decias i me sale el mismo error. Disculpas.
Código Python:
Ver original
  1. import time
  2. from threading import Thread
  3.      
  4. def myfunc(i):
  5.     print "sleeping 5 sec from thread %d" % i
  6.     time.sleep(5)
  7.     print "finished sleeping from thread %d" % i
  8.        
  9. for i in range(10):
  10.     t = Thread(target = myfunc(i))
  11.     t.start()

error:
ImportError: cannot import name sleep

Última edición por razpeitia; 03/04/2013 a las 10:47
  #5 (permalink)  
Antiguo 03/04/2013, 10:49
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Problema libreria time, trheading

Como acabo de ver en el error ponle otro nombre nombre a tu script que no se llame time.py.
  #6 (permalink)  
Antiguo 03/04/2013, 11:20
 
Fecha de Ingreso: marzo-2013
Mensajes: 19
Antigüedad: 11 años, 1 mes
Puntos: 0
Respuesta: Problema libreria time, trheading

Nada el mismo error.

Tambien he intentado poner

from threading import*

pero sale el mismo error.Alguna otra idea?

Gracias.
edit:

pongo el mensaje de error entero:
Traceback (most recent call last):
File "./temps.py", line 2, in <module>
import time
File "/home/admin/Escritorio//time.py", line 17, in <module>
from threading import Thread
File "/usr/lib64/python2.7/threading.py", line 13, in <module>
from time import time as _time, sleep as _sleep
ImportError: cannot import name sleep

Última edición por Victoria222; 03/04/2013 a las 11:33
  #7 (permalink)  
Antiguo 03/04/2013, 12:12
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Problema libreria time, trheading

Cámbiale en nombre al archivo time.py que esta en tu escritorio /home/admin/Escritorio//time.py
  #8 (permalink)  
Antiguo 03/04/2013, 13:52
 
Fecha de Ingreso: marzo-2013
Mensajes: 19
Antigüedad: 11 años, 1 mes
Puntos: 0
Respuesta: Problema libreria time, trheading

Gracias por responder, he cambiado el nombre pero me da el mismo error.

lo he renombrado a prueba_tiempo.py.
y me sigue saliendo el error.

Es un codigo que he copiado de internet, para usar threads pero no consigo que compile.

Gracias!!

saludos
  #9 (permalink)  
Antiguo 03/04/2013, 13:58
Avatar de Carlangueitor
Moderador ლ(ಠ益ಠლ)
 
Fecha de Ingreso: marzo-2008
Ubicación: México
Mensajes: 10.037
Antigüedad: 16 años, 1 mes
Puntos: 1329
Respuesta: Problema libreria time, trheading

Si en el error sigue diciendo esto: "File "/home/admin/Escritorio//time.py", line 17, in <module>" significa que no has cambiado el nombre del archivo. Si no te sale eso entonces es otro error, pegalo aquí.

Saludos
__________________
Grupo Telegram Docker en Español
  #10 (permalink)  
Antiguo 03/04/2013, 15:27
 
Fecha de Ingreso: marzo-2013
Mensajes: 19
Antigüedad: 11 años, 1 mes
Puntos: 0
Respuesta: Problema libreria time, trheading

Este es el error completo:
File "./prova_thread.py", line 2, in <module>
import time
File "/home/admin/Escritorio/time.py", line 17, in <module>
from threading import Thread

File "/usr/lib64/python2.7/threading.py", line 13, in <module>
from time import time as _time, sleep as _sleep
ImportError: cannot import name sleep

gracias por las molestias.

Saludos!!!
  #11 (permalink)  
Antiguo 03/04/2013, 15:40
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Problema libreria time, trheading

Cámbiale el nombre a este archivo.

/home/admin/Escritorio/time.py

O desde la terminal. Ejecuta este comando.

Código:
mv /home/admin/Escritorio/time.py /home/admin/Escritorio/time0.py
  #12 (permalink)  
Antiguo 04/04/2013, 02:10
 
Fecha de Ingreso: marzo-2013
Mensajes: 19
Antigüedad: 11 años, 1 mes
Puntos: 0
Respuesta: Problema libreria time, trheading

Buenas, gracias de nuevo por contestar.

si, ya lo hacia así, he provado el código en otro ordenador y funciona bien.No se si puede ser que tenga alguna libreria desactualizada o algo asi.

Hace poco que estoy con python i no consigo encontrar el fallo

Gracias y saludos!!!

edit:
Uso la version 2.7.3 de python.

Última edición por Victoria222; 04/04/2013 a las 02:27
  #13 (permalink)  
Antiguo 04/04/2013, 11:36
 
Fecha de Ingreso: marzo-2013
Mensajes: 19
Antigüedad: 11 años, 1 mes
Puntos: 0
Respuesta: Problema libreria time, trheading

Gracias a todos por responder.

ya lo he solucionado, resulta que tenia que borrar el time.py y listo. supongo que al re-nombrarlo aun lo intentaba importar desde este.

Gracias!!
Saludos.
  #14 (permalink)  
Antiguo 04/04/2013, 12:11
Avatar de Carlangueitor
Moderador ლ(ಠ益ಠლ)
 
Fecha de Ingreso: marzo-2008
Ubicación: México
Mensajes: 10.037
Antigüedad: 16 años, 1 mes
Puntos: 1329
Respuesta: Problema libreria time, trheading



Es lo que te estábamos diciendo. Renombrarlo o borrarlo.
__________________
Grupo Telegram Docker en Español

Etiquetas: libreria, time
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:55.