python - AttributeError: 'module' 对象没有属性 'lowercase'

标签 python numpy import matplotlib attributeerror

我想我在导入 pylab 时遇到了问题。导入 numpy 时会出现类似的错误。 这是我的代码

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

我得到了这个输出

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'

语法有问题吗?

我在 fedora18 上使用 python2.7。

最佳答案

2020 年附录:注意 string.lowercase 仅适用于 Python 2。

在 Python 3 中,使用 string.ascii_lowercase 而不是 string.lowercase

Python 3.6.8 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
>>> import string
>>> string.lowercase
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'string' has no attribute 'lowercase'
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'

关于python - AttributeError: 'module' 对象没有属性 'lowercase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20552481/

相关文章:

for-loop - Numpy savetxt 循环

python - PyInstaller 无法包含 C :\Python27\Lib 中的某些模块

reactjs - 尝试导入错误: 'reactstrap' does not contain a default export (imported as 'Table' )

python - 计算python中多维数组中数组的出现次数

python - 两个矩形脉冲的卷积 Python

groovy - 如何配置 GroovyConsole 以便我不必在启动时导入库?

python - 路线在生产中被破坏,但在 Pyramid 开发中未被破坏

python - Argparse:未显示子解析器的默认值

python - 替换 N-d numpy 数组中的字符串

python - 模块导入错误,如何刷新Ipython session ?