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."
I was going to use pytz, so used easy_install pytz
This 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?
In my python shell i use from pytz import timezone I get,
"ImportError: No module named pytz"
Any ideas? Thanks in advance
pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference (datetime. tzinfo).
You need to install the pytz package so it's available for your lambda. The way you do this is having pip install it into the directory you are going to zip and upload to AWS (i.e. peered with the file containing your lambda function). Then when you zip it up and upload it, it will be available.
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
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'
For what it's worth, the answer to the fundamental problem here is that the pytz installation process didn't actually extract the ".egg" file (at least, this is what I noticed with a very similar issue.)
You may consider going into the site-packages folder and extracting it yourself.
It is important if you are using python v2 or python v3 - it has separate easy_install package! In debian there are: python-pip python3-pip
and then easy_install easy_install3
If you use wrong version of easy_install you will be updating wrong libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With