2014-10-14 11 views
6

Per quanto posso dire, non ho nemmeno bisogno di pytz per quello che sto facendo.'ImportError: nessun modulo chiamato pytz' quando si tenta di importare pylab?

Sto reimparando python per l'elaborazione delle immagini utilizzando il libro O'Reilly 'Programmazione Computer Vision con Python' per lavoro (e sono anche nuovo per mac, quindi su entrambi i fronti mi scuso se questo è uno stupido domanda). Insieme con una foto 'empire.jpg', sto cercando di eseguire lo script a pagina 16, che va come segue:

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

ma ottengo il seguente output con un errore:

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 

Sto usando OS X 10.9.4. Ho installato matplotlib e numpy da macpython.org e ho installato scipy 0.11.0 tutto per python 2.5.

Ho persino bisogno di pytz? In caso contrario, come posso aggirare questo errore?

+1

Chiaramente '' matplotlib' richiede pytz'; basta installare quel pacchetto? –

+0

Ho provato a installare pytz usando sia easy_install e varie fonti online, ma non sembra fare alcuna differenza. – nale

+0

Ok, ho funzionato ora che ho installato Anaconda 3 con Spyder. Non sono ancora sicuro di cosa diavolo stia facendo. – nale

risposta

15

pylab richiede pytz. Il modo più semplice per installare un pacchetto in Python è eseguire pip install pytz.

Oggi, Python viene fornito con pip pre-installato, ma utilizzare queste istruzioni se è necessario installarlo: https://pip.pypa.io/en/latest/installing.html

Problemi correlati