0

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 python3.4-dev 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 python3.4.0? 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)
Jesse Zhuang
  • 388
  • 1
  • 4
  • 14
  • 1
    Possible duplicate of [Python.h missing from Ubuntu 12.04](http://stackoverflow.com/questions/15631135/python-h-missing-from-ubuntu-12-04) – Swanand Jul 31 '16 at 07:52
  • @Swanand, I clearly mentioned I have tried to install python3.4-dev but met dependency issue. I would prefer not to downgrade my python 3.4.3 if possible. If that must be done, I was asking proper ways to do it. – Jesse Zhuang Jul 31 '16 at 08:35

2 Answers2

1

According to this: http://packages.ubuntu.com/trusty/python3 the official default python3 version of 14.04 from Ubuntu is 3.4.0. According to this: http://packages.ubuntu.com/trusty-updates/python3.4 the newer version came from the updates repo. It is common for distros to have a base repo and an updates repo with newer packages (Fedora does this too). Somehow you installed both, possibly because aptitude failed in some way here.

You have two options here:

  1. Remove the updates package of python3.4 so that you can use the default python-dev.
  2. Remove the default package of python3 so that you can use the updates python3.4-dev.

There is another possibility here, which is that python3.4-dev was built with the wrong dependencies or gathered the wrong dependencies when being built, but the output you have seems to imply otherwise.

The other possibility, which will be a headache, is if apt is failing hard at correctly discerning the dependencies for python3.4-dev.

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
0

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
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 http://us.archive.ubuntu.com/ubuntu/ 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.

Jesse Zhuang
  • 388
  • 1
  • 4
  • 14