I think I'm having troubles importing pylab. A similar error occurs when I import numpy. Here is my code
from math import radians, sin, cos
from pylab import plot, xlabel, ylabel, title, show
v0=input("Enter v0 (m/s)...")
alpha0=input("enter alpha0 (degrees)...")
g=input("Enter g (m/s^2)..")
radalpha0=radians(alpha0)
t_inc=0.01
t=0
i=0
x=[]
y=[]
x.append(v0*cos(radalpha0)*t)
y.append(v0*sin(radalpha0)*t-0.5*g*t*t)
while y[i]>=0:
i=i+1
t=t+t_inc
x.append(v0*cos(radalpha0)*t)
y.append(v0*sin(radalpha0)*t-0.5*g*t*t)
xlabel('x')
ylabel('x')
plot(x,y)
title('Motion in two dimensions')
show()
I get this output
Traceback (most recent call last):
File "2d_motion.py", line 2, in <module>
from pylab import plot, xlabel, ylabel, title, show
File "/usr/lib64/python2.7/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/usr/lib64/python2.7/site-packages/matplotlib/__init__.py", line 151, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/usr/lib64/python2.7/site-packages/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "/usr/lib64/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 28, in <module>
from pyparsing import Literal, ZeroOrMore, \
File "/usr/lib/python2.7/site-packages/pyparsing.py", line 109, in <module>
alphas = string.lowercase + string.uppercase
AttributeError: 'module' object has no attribute 'lowercase'
Is there any problem with the syntax?
I'm using python2.7 on fedora18.
After some discussion in the comments, it turned out (as it usually does when builtin modules suddenly seem to give AttributeErrors
) that the problem was that another module named string
was shadowing the builtin one.
One way to check this is to look at the __file__
attribute of the module, or just look at the repr
itself:
>>> print string
<module 'string' from '/usr/lib/python2.7/string.pyc'>
if the from
doesn't point to the right place, you've got the wrong module being read.
Solution: delete/rename the offending string.py
/string.pyc
files.