Can I re-compile python with an older version of gcc on ubuntu 18.04?

1

Yesterday, I upgraded my OS from ubuntu 16.04 to 18.04.

Since then, one of my python modules (on python 2.7) does not work anymore. Trying to import it yielded an error.

This module uses fortran code with f2py, so I tried using update-alternatives to switch back to gcc-5 and gfotran-5 before making it again.

To some extent, this made the situation better, since python now accepts to import the module. However, it still does not work when I try to use it, throwing errors that begin with:

 capi_return is NULL
 Call-back "some_routine" failed.

Encouraged by this apparent progress, I want to see whether the remaining error is due to a mismatch between the compiler versions used to make the module and python itself. Indeed, python was compiled with gcc 7.3.

Is it possible to re-compile python 2.7 with gcc-5?

What I've tried: After switching to older compiler versions, I went in console mode and did:

 sudo apt-get install --reinstall python

But python still says it was compiled with gcc 7.3.

Could something else have changed between the two OS versions that broke the module?

I want to emphasize that I did not write the module myself, and that it worked fine before the OS upgrade.

Thanks in advance for your suggestions :)

Antoine

Posted 2018-09-05T07:53:24.743

Reputation: 11

FYI, apt doesn't compile programs from source, it installs pre-compiled packages. – gronostaj – 2018-09-05T08:11:24.827

1You would have to find the python source code and recompile "manually". But the problem is more likely a problem of python version or some runtime library. Why don't you update the module instead? – xenoid – 2018-09-05T08:20:32.387

Answers

0

This is because Ubuntu 18.04 does not come with Python2. It comes with Python3 by default. You can easily install python2 along side of python3 though. Then your modules will work again.

You shouldn't need to compile anything. Just install python 2:

sudo apt-get install python2.7

You can check which version is which by using the version argument:

root@server:~/PycharmProjects$ python2 --version
Python 2.7.12
root@server:~/PycharmProjects$ python3 --version
Python 3.5.2

kittyboo

Posted 2018-09-05T07:53:24.743

Reputation: 13