Search code examples
linuxcompiler-errorspython-2.xpython-module

Python build finished, but the necessary bits to build these modules were not found


The official support for python2 ended a few months ago , but I need it to run one of my programs and also it has been removed from the ubuntu 20.04 repository.So I wanted to compile and install python2 myself.But in the closing stages of the make all(in fact in setup.py build) , it prints the following error :

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _ssl            
_tkinter           bsddb185           bz2             
dbm                dl                 gdbm            
imageop            readline           sunaudiodev     
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

I don't care about some modules like readline or _tkinter but I need _ssl.It's not possible to install that via pip.
I installed libssl-dev from the repository but then the following error occurred beside those after re-building:

Failed to build these modules:
_hashlib           _ssl

Any help is appreciated.
Thanks.


Solution

  • To be honest I would rather use a docker image for Python2 than try to compile it; might be overkill for some but for me it's the easier and cleaner way.

    For example if you have a project folder, containing at least project.py and requirements.txt you can use the following Dockerfile (in the same folder as project):

    FROM python:2.7-slim-buster
    
    COPY /project /app
    RUN pip install --no-cache-dir -r /app/requirements.txt
    
    WORKDIR /app
    
    CMD [ "python", "project.py" ]
    

    Build it with docker build -t project .

    Run it with docker run -it --rm --name project_run project

    Depending on how complex your application is you can also try to bring it up to date so it will run on Python 3 (there are also automated tools to help you with this).