无法在 Python 2.7 或 Python 3.3 中导入十进制 [英] Unable to import decimal in Python 2.7 or Python 3.3

查看:54
本文介绍了无法在 Python 2.7 或 Python 3.3 中导入十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 Python 2.7 或 3.3 的终端中导入十进制.

I am unable to import decimal in the terminal for Python 2.7 or 3.3.

这是我得到的错误:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/decimal.py", line 3849, in <module>
    _numbers.Number.register(Decimal)
AttributeError: 'module' object has no attribute 'Number'

或 Python 2.7

or Python 2.7

Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py", line 141, in <module>
    import numbers as _numbers
  File "numbers.py", line 34, in <module>
    assert x / y == 2.5 # true division of x by y
AssertionError

如何导入十进制?

推荐答案

当前工作目录下是否有numbers.py?

Is there numbers.py in current working directory?

这可能是问题的原因,因为这会阻止导入标准库模块 numbers.

That could be the reason of the problem, because that prevent import of standard library module numbers.

这篇关于无法在 Python 2.7 或 Python 3.3 中导入十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆