Pycharm MySQLdb'module'对象没有属性'Number'

时间:2014-10-22 20:20:38

标签: pycharm mysql-python

以下程序使用python脚本执行得很好,并为我提供了预期的输出:

Database version : 5.6.19-0ubuntu0.14.04.1 

然而,完全相同的程序似乎不适用于Pycharm。

输出:

/usr/bin/python2.7 /home/shog/PycharmProjects/PythonAdvancedTutorial/Databases.py
Traceback (most recent call last):

  File "/home/shog/PycharmProjects/PythonAdvancedTutorial/Databases.py", line 12, in <module>

    db = MySQLdb.connect('localhost', 'root', '*****', 'TESTDB')

  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/connections.py", line 147, in __init__
    from MySQLdb.converters import conversions

  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b4-py2.7-linux-x86_64.egg/MySQLdb/converters.py", line 174, in <module>
    from decimal import Decimal

  File "/usr/lib/python2.7/decimal.py", line 3743, in <module>
    _numbers.Number.register(Decimal)
AttributeError: 'module' object has no attribute 'Number'

以下是该计划:

#!/usr/bin/python
import MySQLdb

db = MySQLdb.connect('localhost', 'root', '2soid', 'TESTDB')

cursor = db.cursor()

cursor.execute("SELECT VERSION()")

data = cursor.fetchone()

print "Database version : %s " % data

db.close()

1 个答案:

答案 0 :(得分:0)

删除#!/usr/bin/python或将其更改为#!/usr/bin/env python,您可能会调用错误的Python库