【问题标题】:How to Correctly install MySQL module in Python如何在 Python 中正确安装 MySQL 模块
【发布时间】:2021-04-01 04:18:10
【问题描述】:

我是编码和 ubuntu 的新手,我正在尝试使用 Python 向 MySQL 插入一些数据,但在安装 mysql 模块时遇到了一些错误。

我遇到了这个错误:

**pip install mysql**
Defaulting to user installation because normal site-packages is not writeable
Collecting mysql
  Using cached mysql-0.0.2.tar.gz (1.9 kB)
Collecting mysqlclient
  Using cached mysqlclient-2.0.2.tar.gz (88 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py'"'"'; __file__='"'"'/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ocgktfp6
         cwd: /tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/
    Complete output (12 lines):
    /bin/sh: 1: mysql_config: not found
    /bin/sh: 1: mariadb_config: not found
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup_posix.py", line 65, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-8pt10wd4/mysqlclient_5e8d8ff6d905420ea115c27e23267248/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

【问题讨论】:

  • pip install mysql-connector-python 试试这个,如果你仍然遇到这个问题,检查你的python版本,确保它是python3.8及以上
  • 非常感谢!我能够成功连接它!
  • 好的那我就搬过来回答

标签: python mysql database ubuntu mysql-connector-python


【解决方案1】:

您好,欢迎使用 Python!用于与 MySQL 数据库服务器交互的流行库是“PyMySQL”,可以在以下位置找到:https://pypi.org/project/PyMySQL/

安装命令:

pip install pymysql

您可以在此处查看示例用法:https://pypi.org/project/PyMySQL/#example

【讨论】:

    【解决方案2】:

    pip install mysql-connector-python试试这个,如果你还是遇到这个问题,检查你的python版本,确保它是python3.8及以上。

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 2020-10-23
      • 1970-01-01
      • 2017-05-31
      • 2021-06-25
      • 1970-01-01
      • 2017-05-15
      • 2010-09-14
      • 1970-01-01
      相关资源
      最近更新 更多