Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ImportError: No module named pytz' when trying to import pylab?

As far as I can tell, I don't even need pytz for what I'm doing.

I'm re-learning python for image processing using the O'Reilly book 'Programming Computer Vision with Python' for work (and I'm also new to mac, so on both counts I apologise if this is a stupid question). Along with a 'empire.jpg' picture, I'm trying to run the script on page 16 which goes as follows:

from PIL import Image
from pylab import *
# read image to array
im = array(Image.open('empire.jpg')) # plot the image
imshow(im)
# some points
x = [100,100,400,400]
y = [200,500,200,500]
# plot the points with red star-markers
plot(x,y,'r*')
# line plot connecting the first two points
plot(x[:2],y[:2])
# add title and show the plot
title('Plotting: "empire.jpg"')
show()

but I get the following output with an error:

  File "plotch1.py", line 2, in <module>
    from pylab import *
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pylab.py", line 208, in <module>
    from matplotlib import mpl  # pulls in most modules
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/mpl.py", line 4, in <module>
    from matplotlib import axes
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 18, in <module>
    from matplotlib import dates as mdates
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/dates.py", line 82, in <module>
    import pytz
ImportError: No module named pytz

I'm using OS X 10.9.4. I've installed matplotlib and numpy from macpython.org and I've installed scipy 0.11.0 all for python 2.5.

Do I even need pytz? If not, how can I get around this error?

like image 706
nale Avatar asked Oct 14 '14 10:10

nale


People also ask

How do I fix No module named pytz?

The Python "ModuleNotFoundError: No module named 'pytz'" occurs when we forget to install the pytz module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install pytz command.

Is pytz included in Python?

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).

How do I import pytz to AWS Lambda?

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.


2 Answers

pylab requires pytz. The easiest way to install a package in Python is to run pip install pytz.

Today, Python comes with pip pre-installed, but use these instructions if you need to install it: Installation: Do I need to install pip?

like image 88
Itay Kahana Avatar answered Oct 18 '22 19:10

Itay Kahana


Firstly if you have installed pip then remove it by deleting the folder of pip inside python directory. Then install pip by this command:

$ sudo easy_install pip

Then you need to install pytz again by this command:

$ sudo pip install pytz

Don't update pip to 10th version because it might contain bugs which is causing problems.

like image 9
Vicrobot Avatar answered Oct 18 '22 20:10

Vicrobot