【问题标题】:How to install python-mysqldb for Python 2.7 in Ubuntu 20.04 (Focal Fossa)?如何在 Ubuntu 20.04 (Focal Fossa) 中为 Python 2.7 安装 python-mysqldb?
【发布时间】:2020-12-06 23:09:54
【问题描述】:

我试过“apt-get install python-mysqldb”,结果是:

root@ps1svr:~# apt-get install python-mysqldb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package python-mysqldb is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-mysqldb' has no installation candidate

注意:“apt-get install python3-mysqldb”有效,但是我有很多为 Python 2.x 编写的代码不再运行,这导致了很多问题,我可能不得不重新安装Ubuntu 18.04

【问题讨论】:

  • 您是否尝试过在运行安装之前运行“apt-get update”?
  • 你不应该期望获得对 Python 2 的任何支持。它已在今年年初达到生命的尽头。你应该专注于让你的代码与 Python 3 一起工作。
  • 谢谢帕特里克,但我在运行安装之前做了“apt-get update”。
  • 谢谢 mkrieger1,我知道 Python 2.x 已经到了生命周期的尽头,但我在一个我们有很多计算机的环境中工作,运行各种版本的 Linux。一些最古老的嵌入式系统与中型 (1.8m) 望远镜相关联,因此两个弊端中较小的一个将是回滚到 Ubuntu 18.04 并继续使用它,而不是重写所有内容以使用 Python 3。跨度>
  • 这个页面可能会让人们相信 python-mysqldb 可能在 20.04 可用:(ubuntuupdates.org/package/core/focal/main/base/python-mysqldb)

标签: python-2.7 ubuntu mysql-python


【解决方案1】:

这将使用 pip 为所有用户下载、构建和安装它

sudo apt install libmysqlclient-dev python2.7-dev

wget https://bootstrap.pypa.io/get-pip.py
sudo python2.7 get-pip.py

sudo wget https://raw.githubusercontent.com/paulfitz/mysql-connector-c/master/include/my_config.h -O /usr/include/mysql/my_config.h

sudo pip2 install MySQL-python

MySQLdb install error - _mysql.c:44:23: error: my_config.h: No such file or directory找到答案

【讨论】:

    【解决方案2】:

    您也可以添加 Ubuntu 18.04 存储库来安装 python-mysqldb 包:

    sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu bionic main'
    sudo apt update
    sudo apt install -y python-mysqldb
    

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 2020-11-11
      • 2013-04-21
      • 2017-09-13
      • 1970-01-01
      • 2021-04-15
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多