【问题标题】:ImportError: No module named MySQLdb Python2.7ImportError:没有名为 MySQLdb Python2.7 的模块
【发布时间】:2020-04-16 20:20:52
【问题描述】:

我无法安装任何东西来修复它。我尝试了以下命令。

pip install MySQL-python when I run this please see the screen shot in error

pip install mysqlclient brew install mysql brew install libmysqlclient-dev

more pictures [![enter image description here][1]][1][![enter image description here][1]][1]



  PASML-1717136:server $ Python2.7 main.py
    Traceback (most recent call last):
      File "main.py", line 68, in <module>
        HANDLER = get_handlers()
      File "main.py", line 59, in get_handlers
        adapter = MysqlAdapter(CONFIG.DB_CONN)
      File "/Users/mnaeem668/Projects/Automation_KPI/server/../server/adapters/mysql_adapter.py", line 24, in __init__
        self._connect()
      File "/Users/mnaeem668/Projects/Automation_KPI/server/../server/adapters/mysql_adapter.py", line 33, in _connect
        self.engine = create_engine(conn_str)
      File "/Library/Python/2.7/site-packages/sqlalchemy/engine/__init__.py", line 479, in create_engine
        return strategy.create(*args, **kwargs)
      File "/Library/Python/2.7/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
        dbapi = dialect_cls.dbapi(**dbapi_args)
      File "/Library/Python/2.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi
        return __import__("MySQLdb")
    ImportError: No module named MySQLdb
    Exception AttributeError: "'NoneType' object has no attribute 'close'" in <bound method MysqlAdapter.__del__ of <server.adapters.mysql_adapter.MysqlAdapter object at 0x11240cb50>> ignored

更新:安装 python-MySQLdb

ERROR: Could not find a version that satisfies the requirement python-MySQLdb (from versions: none)
ERROR: No matching distribution found for python-MySQLdb

【问题讨论】:

    标签: python python-2.7 mysql-python


    【解决方案1】:

    您似乎正在尝试安装 python-mysql 而没有在您的机器上安装 mysql 及其依赖项。 从您的屏幕截图看来,您正在 MacOS 上运行。 请看下面的评论:

    mySQLdb 是mysql 的python 接口,但它不是mysql 本身。显然 mySQLdb 需要命令 'mysql_config',所以你需要先安装它。

    您能否通过从 shell 运行“mysql”来确认您是否安装了 mysql 本身?这应该会给你一个响应,而不是“mysql:找不到命令”。

    并查看以下关于在 MacOS 上安装的评论 mysql_config not found when installing mysqldb python interface

    【讨论】:

      猜你喜欢
      • 2014-04-10
      • 2018-07-15
      • 2019-08-20
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      • 2015-08-19
      • 2016-05-11
      • 2016-03-05
      相关资源
      最近更新 更多