install后没有名为pytz的模块

install后没有名为pytz的模块

本文介绍了导入错误:使用easy_install后没有名为pytz的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天是我在 Python 的第一天,一直在解决问题.我正在做的一个是,编写一个简短的程序,从操作系统中提取当前日期和时间,并以下列格式将其打印在屏幕上:日、月、年、格林威治标准时间的当前时间.证明它有效."

Today is my first day at Python and have been going through problems. One that I was working on was, "Write a short program which extracts the current date and time from the operating system and prints it on screen in the following format: day, month, year, current time in GMT.Demonstrate that it works."

我打算用pytz,所以用了easy_install pytz这将它安装在我的站点包 (pytz-2012d-py2.7.egg) 中

I was going to use pytz, so used easy_install pytzThis installed it in my site-packages (pytz-2012d-py2.7.egg)

这是我能够导入模块的正确目录吗?

Is this the correct directory for me to be able to import the module?

在我的 python shell 中,我使用 from pytz import timezone 我得到,导入错误:没有名为 pytz 的模块"

In my python shell i use from pytz import timezone I get,"ImportError: No module named pytz"

有什么想法吗?提前致谢

Any ideas? Thanks in advance

推荐答案

time 模块也可以在这里提供帮助..UTC 是协调世界时(以前称为格林威治标准时间,或 GMT)

time module can also help here..UTC is Coordinated Universal Time (formerly known as Greenwich Mean Time, or GMT)

In [18]: import time

In [19]: time.gmtime()
Out[19]: time.struct_time(tm_year=2012, tm_mon=9, tm_mday=22, tm_hour=3, tm_min=37, tm_sec=15, tm_wday=5, tm_yday=266, tm_isdst=0)

In [20]: x = time.gmtime()

In [21]: x.tm_year
Out[21]: 2012

In [22]: x.tm_mon
Out[22]: 9

In [23]: x.tm_mday
Out[23]: 22

In [24]: x.tm_hour
Out[24]: 3

您还可以在安装 pytz 时检查日志,并使用以下...

Also can you Check the logs while you installed pytz with the below ones...

C:\>easy_install pytz
Searching for pytz
Reading http://pypi.python.org/simple/pytz/
Reading http://pytz.sourceforge.net
Reading http://sourceforge.net/project/showfiles.php?group_id=79122
Reading http://www.stuartbishop.net/Software/pytz
Reading http://sourceforge.net/projects/pytz/
Best match: pytz 2012d
Downloading http://pypi.python.org/packages/2.7/p/pytz/pytz-2012d-py2.7.egg#md5=
e6f9219ae6eff242f13c6700413df69e
Processing pytz-2012d-py2.7.egg
Moving pytz-2012d-py2.7.egg to c:\python27\lib\site-packages
Adding pytz 2012d to easy-install.pth file

Installed c:\python27\lib\site-packages\pytz-2012d-py2.7.egg
Processing dependencies for pytz
Finished processing dependencies for pytz

C:\>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytz
>>> from datetime import datetime, timedelta
>>> utc = pytz.utc
>>> utc.zone
'UTC'

这篇关于导入错误:使用easy_install后没有名为pytz的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:03