Import Error: No module named pytz after using easy_install

2024/5/20 10:22:36

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

Answer

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

In [18]: import timeIn [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]: 2012In [22]: x.tm_mon
Out[22]: 9In [23]: x.tm_mday
Out[23]: 22In [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 fileInstalled c:\python27\lib\site-packages\pytz-2012d-py2.7.egg
Processing dependencies for pytz
Finished processing dependencies for pytzC:\>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'
https://en.xdnf.cn/q/72936.html

Related Q&A

Python catch exception pandas.errors.ParserError: Error tokenizing data. C error

I am facing problem with my malfunction csv input file whole reading and which i can deal with by adding "error_bad_lines=False" in my read_csv func to remove those.But i need to report these…

Nested tags in BeautifulSoup - Python

Ive looked at many examples on websites and on stackoverflow but I couldnt find a universal solution to my question. Im dealing with a really messy website and Id like to scrape some data. The markup l…

How do I check if a string is a negative number before passing it through int()?

Im trying to write something that checks if a string is a number or a negative. If its a number (positive or negative) it will passed through int(). Unfortunately isdigit() wont recognize it as a numbe…

openpyxl chage font size of title y_axis.title

I am currently struggling with changing the font of y axis title & the charts title itself.I have tried to create a font setting & applying it to the titles - with no luck what so ever. new_cha…

Combination of all possible cases of a string

I am trying to create a program to generate all possible capitalization cases of a string in python. For example, given abcedfghij, I want a program to generate: Abcdefghij ABcdef.. . . aBcdef.. . ABCD…

How to change download directory location path in Selenium using Chrome?

Im using Selenium in Python and Im trying to change the download path. But either this: prefs = {"download.default_directory": "C:\\Users\\personal\\Downloads\\exports"} options.add…

Keras, TensorFlow : TypeError: Cannot interpret feed_dict key as Tensor

I am trying to use keras fune-tuning to develop image classify applications. I deployed that application to a web server and the image classification is succeeded.However, when the application is used …

How to get matplotlib to place lines accurately?

By default, matplotlib plot can place lines very inaccurately.For example, see the placement of the left endpoint in the attached plot. Theres at least a whole pixel of air that shouldnt be there. In f…

Using Flask as pass through proxy for file upload?

Its for app engines blobstore since its upload interface generates a temporary endpoint every time. Id like to take the comlexity out of frontend, Flask would take the post request and forward it to th…

What does printing an empty line do?

I know this question may well be the silliest question youve heard today, but to me it is a big question at this stage of my programming learning.Why is the second empty line needed in this Python code…