尝试在 Ubuntu 20.04 上安装 mysqlclient 以用于 Django 项目
sudo apt-get install python3.7-dev libmysqlclient-dev
但出现以下错误
python3.7-dev is already the newest version (3.7.7-1+bionic1).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libmysqlclient-dev : Depends: libssl-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
然后尝试安装 libssl-dev
sudo apt install libssl-dev
获取错误
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libssl-dev : Depends: libssl1.1 (= 1.1.1f-1ubuntu2) but 1.1.1g-1+ubuntu18.04.1+deb.sury.org+1 is to be installed
E: Unable to correct problems, you have held broken packages.
很高兴能得到有关此类问题的任何信息
更新为了 apt-cache 策略 python3.7-dev libmysqlclient-dev libssl-dev zlib1g-dev
python3.7-dev:
Installed: 3.7.7-1+bionic1
Candidate: 3.7.7-1+bionic1
Version table:
*** 3.7.7-1+bionic1 100
100 /var/lib/dpkg/status
libmysqlclient-dev:
Installed: (none)
Candidate: 8.0.20-0ubuntu0.20.04.1
Version table:
8.0.20-0ubuntu0.20.04.1 500
500 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
8.0.19-0ubuntu5 500
500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
libssl-dev:
Installed: (none)
Candidate: 1.1.1f-1ubuntu2
Version table:
1.1.1f-1ubuntu2 500
500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
zlib1g-dev:
Installed: 1:1.2.11.dfsg-2ubuntu1
Candidate: 1:1.2.11.dfsg-2ubuntu1
Version table:
*** 1:1.2.11.dfsg-2ubuntu1 500
500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
100 /var/lib/dpkg/status
更新2为了apt-cache 策略
Package files:
100 /var/lib/dpkg/status
release a=now
100 http://us.archive.ubuntu.com/ubuntu focal-backports/universe i386 Packages
release v=20.04,o=Ubuntu,a=focal-backports,n=focal,l=Ubuntu,c=universe,b=i386
origin us.archive.ubuntu.com
100 http://us.archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal-backports,n=focal,l=Ubuntu,c=universe,b=amd64
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages
release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=universe,b=i386
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=universe,b=amd64
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages
release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=main,b=i386
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
release v=20.04,o=Ubuntu,a=focal-updates,n=focal,l=Ubuntu,c=main,b=amd64
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal/universe i386 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=i386
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=amd64
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal/main i386 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=main,b=i386
origin us.archive.ubuntu.com
500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=main,b=amd64
origin us.archive.ubuntu.com
Pinned packages:
答案1
您不需要重新安装 ubuntu 20.04 来安装mysqlclient
。您只需按照以下步骤操作即可。
步骤 0: sudo apt install python3-dev build-essential
步骤1: sudo apt install libssl1.1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libssl1.1 is already the newest version (1.1.1j-1+ubuntu18.04.1+deb.sury.org+3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
第2步: sudo apt install libssl1.1=1.1.1f-1ubuntu2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be DOWNGRADED:
libssl1.1
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
Need to get 1318 kB of archives.
After this operation, 76.8 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal/main amd64 libssl1.1 amd64 1.1.1f-1ubuntu2 [1318 kB]
Fetched 1318 kB in 2s (656 kB/s)
Preconfiguring packages ...
dpkg: warning: downgrading libssl1.1:amd64 from 1.1.1j-1+ubuntu18.04.1+deb.sury.org+3 to 1.1.1f-1ubuntu2
(Reading database ... 131148 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1f-1ubuntu2_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1f-1ubuntu2) over (1.1.1j-1+ubuntu18.04.1+deb.sury.org+3) ...
Setting up libssl1.1:amd64 (1.1.1f-1ubuntu2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
步骤3: sudo apt install libssl-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libssl1.1
Suggested packages:
libssl-doc
The following NEW packages will be installed:
libssl-dev
The following packages will be upgraded:
libssl1.1
1 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 2902 kB of archives.
After this operation, 8006 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl1.1 amd64 1.1.1f-1ubuntu2.3 [1320 kB]
Get:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 libssl-dev amd64 1.1.1f-1ubuntu2.3 [1582 kB]
Fetched 2902 kB in 2s (1449 kB/s)
Preconfiguring packages ...
(Reading database ... 131149 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1f-1ubuntu2.3_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1f-1ubuntu2.3) over (1.1.1f-1ubuntu2) ...
Selecting previously unselected package libssl-dev:amd64.
Preparing to unpack .../libssl-dev_1.1.1f-1ubuntu2.3_amd64.deb ...
Unpacking libssl-dev:amd64 (1.1.1f-1ubuntu2.3) ...
Setting up libssl1.1:amd64 (1.1.1f-1ubuntu2.3) ...
Setting up libssl-dev:amd64 (1.1.1f-1ubuntu2.3) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
步骤4: sudo apt install libmysqlclient-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libmysqlclient21
The following NEW packages will be installed:
libmysqlclient-dev libmysqlclient21
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 2760 kB of archives.
After this operation, 17.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 libmysqlclient21 amd64 8.0.23-0ubuntu0.20.04.1 [1224 kB]
Get:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 libmysqlclient-dev amd64 8.0.23-0ubuntu0.20.04.1 [1536 kB]
Fetched 2760 kB in 2s (1663 kB/s)
Selecting previously unselected package libmysqlclient21:amd64.
(Reading database ... 131266 files and directories currently installed.)
Preparing to unpack .../libmysqlclient21_8.0.23-0ubuntu0.20.04.1_amd64.deb ...
Unpacking libmysqlclient21:amd64 (8.0.23-0ubuntu0.20.04.1) ...
Selecting previously unselected package libmysqlclient-dev.
Preparing to unpack .../libmysqlclient-dev_8.0.23-0ubuntu0.20.04.1_amd64.deb ...
Unpacking libmysqlclient-dev (8.0.23-0ubuntu0.20.04.1) ...
Setting up libmysqlclient21:amd64 (8.0.23-0ubuntu0.20.04.1) ...
Setting up libmysqlclient-dev (8.0.23-0ubuntu0.20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
步骤5: pip3 install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.0.3.tar.gz (88 kB)
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (setup.py) ... done
Created wheel for mysqlclient: filename=mysqlclient-2.0.3-cp38-cp38-linux_x86_64.whl size=109322 sha256=767a28ae7685c9344c118572f613a83e8c58f597a2dc776f28dbe708188ba044
Stored in directory: /home/ubuntu/.cache/pip/wheels/3a/c1/c3/5a19639a551c921c2c2b39468f4278ce5aa27b4e386a4158e4
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.0.3
就是这样!
现在,您可以通过 Django 享受 MySQL 了。
答案2
解决方案是从头开始完全重新安装 Ubuntu 20.04,因为操作系统存在不同的问题。之前的操作系统是从 16.04 版本升级的。之后 mysqlclient 已成功安装。
答案3
你必须删除旧的python
sudo apt-get remove python3.7-dev
sudo apt-get autoremove
然后使用更新软件包列表
sudo apt-get update
并安装软件:
sudo apt-get install libmysqlclient-dev