3

Trying to install mysqlclient on Ubuntu 20.04 to use in Django project

sudo apt-get install python3.7-dev libmysqlclient-dev

But get the following error

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.

Then trying to install libssl-dev

sudo apt install libssl-dev

Get the error

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.

Will be glad for any information in such problem

UPDATE for apt-cache policy 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

UPDATE 2 for apt-cache policy

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:
8
  • Please add output of apt-cache policy python3.7-dev libmysqlclient-dev libssl-dev zlib1g-dev to the question.
    – N0rbert
    May 25 '20 at 18:58
  • Hello N0rbert Just added it
    – AlexKh
    May 25 '20 at 19:06
  • Sorry N0rbert It was on the other machine, I've just changed the updates for the other one
    – AlexKh
    May 25 '20 at 19:12
  • 1
    Then please check all commands again, the "apt-cache policy" is correct now.
    – N0rbert
    May 25 '20 at 19:14
  • Just added to UPDATE 2
    – AlexKh
    May 25 '20 at 19:16
1

The solution was to fully reinstall Ubuntu 20.04 from scratch because there were different problems in OS. The previous OS was upgraded from 16.04 version. After that mysqlclient was successfully installed.

0

You have to remove remove old python with

sudo apt-get remove python3.7-dev
sudo apt-get autoremove

Then update package lists with

sudo apt-get update

and install the software:

sudo apt-get install libmysqlclient-dev
1
  • Unfortunately, it doesn't work It returns: "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."
    – AlexKh
    May 25 '20 at 21:07
0

You don't need to reinstall ubuntu 20.04 to install mysqlclient. You just need to follow these steps.

Step 0: sudo apt install python3-dev build-essential

Step 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.

Step 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) ...

Step 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) ...

Step 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) ...

Step 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

That's it!

Now, you can enjoy MySQL with Django.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.