我不能在python.3上运行matplotlib

时间:2014-05-21 20:55:15

标签: python python-3.x matplotlib

我有这段代码:

import random
import matplotlib.pyplot as plotttt

def simular (N):

  Nd=N
  c=0

  while Nd>(N/2-1):
      r=random.uniform(0,1)

      if r<Nd/float(N):
         Nd=Nd-1

      else:
         Nd=Nd+1

      c+=1

  return c

def main ():

   Nmax=400
   repeticiones=100

   x=[]
   y=[]

   for j in range (2,Nmax):

       promedio=0

       for i in range (0,repeticiones):
           promedio+=simular(j)

       y.append(promedio/repeticiones)
       x.append(j)

   plotttt.plot (x,y,"bo")
   plotttt.show()

main()

但是当我尝试通过终端运行时,会出现下一个错误:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1519, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/__init__.py", line 124, in <module>
    import pyparsing
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pyparsing.py", line 65, in <module>
    import string.ascii_lowercase
ImportError: No module named 'string.ascii_lowercase'; string is not a package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "simulacion.py", line 2, in <module>
    import matplotlib.pyplot as plotttt
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/matplotlib/__init__.py", line 126, in <module>
    raise ImportError("matplotlib requires pyparsing")
ImportError: matplotlib requires pyparsing
Vicente-Gomezs-MacBook-Pro:Python Vicente$ 

但是当我在IDLE上运行它时没有问题。想法?

0 个答案:

没有答案