美文网首页pippython
【pip】Linux上使用pip安装 mysqlclient p

【pip】Linux上使用pip安装 mysqlclient p

作者: Bogon | 来源:发表于2025-01-13 10:33 被阅读0次

Linux 执行报错,如何处理?

# pip  install mysqlclient

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: Running pip install with root privileges is generally not a good idea. Try pip install --user instead.
Collecting mysqlclient
  Using cached mysqlclient-1.4.6.tar.gz (85 kB)
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python2 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-Q7lPLC/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-Q7lPLC/mysqlclient/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-D9GDik
         cwd: /tmp/pip-install-Q7lPLC/mysqlclient/
    Complete output (12 lines):
    sh: mysql_config: command not found
    sh: mariadb_config: command not found
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-Q7lPLC/mysqlclient/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 61, in get_config
        libs = mysql_config("libs")
      File "setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    EnvironmentError: mysql_config not found
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.2.2; however, version 20.3.4 is available.
You should consider upgrading via the '/usr/bin/python2 -m pip install --upgrade pip' command.

在 CentOS 上安装 mysqlclient 时,出现了 mysql_config not found 错误。这是因为 mysqlclient 依赖于 MySQL 或 MariaDB 的开发工具,而这些工具没有被安装。以下是解决这个问题的步骤:

1. 安装 MySQL 或 MariaDB 的开发包

你需要安装 MySQL 或 MariaDB 的开发包,具体取决于你的系统使用的是哪个数据库。

  • 对于 MySQL,安装 MySQL 开发包:

    sudo yum install mysql-devel
    
  • 对于 MariaDB,安装 MariaDB 开发包:

    sudo yum install mariadb-devel
    

2. 确认 Python 版本

你正在使用的是 Python 2.7,而 Python 2 已经停止维护,不再接受更新和支持。强烈建议你升级到 Python 3。你可以使用以下命令检查当前的 Python 版本:

python --version

3. 升级 pip

你还可以尝试升级 pip 到最新版本,尤其是在你遇到警告时,当前使用的是较旧的版本。升级 pip 的命令如下:

python -m pip install --upgrade pip

4. 重新安装 mysqlclient

安装了开发包并且升级了 Python 和 pip 后,重新运行以下命令安装 mysqlclient

pip install mysqlclient

如果你使用的是 Python 3,可以改为:

pip3 install mysqlclient

5. 使用 --user 安装

如果你遇到权限问题,可以使用 --user 标志以避免使用 root 权限:

pip install --user mysqlclient

这样应该可以解决 mysql_config not found 错误,并成功安装 mysqlclient

相关文章

网友评论

    本文标题:【pip】Linux上使用pip安装 mysqlclient p

    本文链接:https://www.haomeiwen.com/subject/rxavyjtx.html