Search code examples
pythonmoduleversionpackagingpypi

How can I allow python users with a version lower than python2.7 to run my program that uses `sysconfig`?


I made a python program which uses the sysconfig module. How can I allow python users with a python version lower than python2.7 to also run that program? I can not find this library in PyPI.

Before I had also used argparse and this was also not installed by default in python versions lower than python2.7. But I could just add it in my requirements file because it can be downloaded using pip.


Solution

  • You'll need to write a version of your code that works without sysconfig - your code would look something like this:

    try:
        import sysconfig
        HAS_SYSCONFIG = True
    except ImportError:
        HAS_SYSCONFIG = False
    
    ...
    
    if HAS_SYSCONFIG:
        # sysconfig code here
    else:
        # compatibility code here
    

    You could also try backporting sysconfig to an earlier version of python and including it with your script, but that may be more work than it's worth.