Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check the version of python a module supports?

Tags:

python

pypi

I was wondering if there is a generic way to find out if your version of python is supported by a specific module?

For example, let us say that I have python 3.11 installed on my computer and I want to install the modules biopython and lru-dict. Going to their respective pypi entries biopython shows this in their Project description:

Python Requirements

We currently recommend using Python 3.10 from http://www.python.org

Biopython is currently supported and tested on the following Python implementations:

Python 3.7, 3.8, 3.9, 3.10 and 3.11 – see http://www.python.org

PyPy3.7 v7.3.5 – or later, see http://www.pypy.org

However, if we check the lru-dict entry, their Project description does not mention Python requirements. I did eventually find out that python 3.11 is not supported by finding a issue on their github page.

Is there a simpler way of finding this information out?

like image 969
Marcelo Paco Avatar asked Sep 03 '25 16:09

Marcelo Paco


2 Answers

If you go to the https://pypi.org/pypi/PACKAGE_NAME/json address, you will receive complete information about Python PACKAGE_NAME in JSON format. For example, to view information about lru-dict open https://pypi.org/pypi/lru-dict/json link, Then you can extract the necessary information from it.

To see the Python version that PACKAGE_NAME is supported, I wrote this code, I hope it suits you.

import json
import pprint
from urllib import request

package_name = 'lru-dict'

with request.urlopen(f'https://pypi.org/pypi/{package_name}/json') as response:
    data = json.loads(response.read())
    pprint.pprint(data['info']['classifiers'])

Output:

 ['Development Status :: 5 - Production/Stable',
 'Intended Audience :: Developers',
 'License :: OSI Approved :: MIT License',
 'Operating System :: OS Independent',
 'Operating System :: POSIX',
 'Programming Language :: C',
 'Programming Language :: Python :: 2',
 'Programming Language :: Python :: 3',
 'Programming Language :: Python :: 3.10',
 'Programming Language :: Python :: 3.6',
 'Programming Language :: Python :: 3.7',
 'Programming Language :: Python :: 3.8',
 'Programming Language :: Python :: 3.9',
 'Programming Language :: Python :: Implementation :: CPython',
 'Topic :: Software Development :: Libraries :: Python Modules']

In addition to viewing the supported Python version, you can also get other information such as the Python version required for each release, package description, author's name, etc.

like image 88
kamyarmg Avatar answered Sep 05 '25 09:09

kamyarmg


No, there is no generic way.

If the library has tests you can run them and check, but it might give you false positives as well as false negatives :shrug:

The lru-dict has this fragment in their setup.py, which is one of the places you can check for supported versions:

        'Programming Language :: C',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
        'Programming Language :: Python :: 3.10',
        'Programming Language :: Python :: 3.11',
        'Programming Language :: Python :: Implementation :: CPython',

So as you can see, I don't think they knew about the issue.

like image 42
yjay Avatar answered Sep 05 '25 11:09

yjay