Jesse Zhuang Jesse Zhuang - 1 year ago 103
Python Question

What's the correct way to add Python.h and/or python3-dev in Ubuntu 14.04?

On Ubuntu 14.04.4 LTS I was trying to install courseara-dl with the default python 3.4.3 and met the error:

src/MD2.c:31:20: fatal error: Python.h: No such file or directory
#include "Python.h"
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Failed building wheel for pycrypto

I have seen some answers mentioning installing
to solve this problem. But there is dependency error:

The following packages have unmet dependencies:
python3.4-dev : Depends: python3.4 (= 3.4.0-2ubuntu1) but 3.4.3-1ubuntu1~14.04.3 is to be installed
Depends: libpython3.4-dev (= 3.4.0-2ubuntu1) but it is not going to be installed
Depends: libpython3.4 (= 3.4.0-2ubuntu1) but 3.4.3-1ubuntu1~14.04.3 is to be installed
Depends: libexpat1-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

What is the recommended way to fix this? Do I have to downgrade to
? If so, what's the proper way to do that?

When I run
dpkg -l | grep python 3
, I see both 3.4.0 and 3.4.3. Should I try
apt-get uninstall 3.4.3

ii python3 3.4.0-0ubuntu2 amd64 interactive high-level object-oriented language (default python3 version)
ii python3.4 3.4.3-1ubuntu1~14.04.3 amd64 Interactive high-level object-oriented language (version 3.4)

Answer Source

I don't remember exactly how I got python 3.4.3 in my Ubuntu, maybe through ubuntu auto upgrade?

The problem was libexpat1:

apt-cache policy libexpat1
  Installed: 2.1.0-4ubuntu1.1
  Candidate: 2.1.0-4ubuntu1.1
  Version table:
 *** 2.1.0-4ubuntu1.1 0
        100 /var/lib/dpkg/status
     2.1.0-4ubuntu1 0
        500 trusty/main amd64 Packages

version 2.1.0-4ubuntu1 was needed for python3-dev and version 2.1.0-4ubntu1.1 was installed.

I also removed python3.4.3 and had to reinstall python3 (python3.4.0).

After that, I was able to install python3-dev.

Similar problems exist for my python2 where I had python2.7.6 but python-dev requires python2.7.5. I did not borther to downgrade python2 since I am not really using it at the moment.

Thanks @matt-schuchard Matt Schuchard for pointing a direction. I am still not sure everything is correct but at least I was able to install python3-dev.