简体   繁体   中英

making python pip figure out the correct package version to download

I have been running into this problem several times. Basically, at work we use an old version of python (2.5) on windows, and often when I do for example pip install zope.interface pip always downloads the latest version of the package, regardless whether that package is supported on my version of python or not. So the example above would downloads 4.0.1 although that PKG-INFO does not list python 2.5 as a supported version and hence I get an installation error

  File "C:\Users\jamaam\build\zope.interface\setup.py", line 42
except DistutilsPlatformError as e:

I would like pip to be more intelligent and installs the highest version of the package that is supported by my python version (in this instance 3.8.0 ) with possibly warning that this package isn't the latest, without me having to search the interweb to manually find the installable version on my environment.

Is there anyway to do so?

Here is some of the content of PKG-INFO which clearly does not list python 2.5

381 Classifier: Operating System :: OS Independent
382 Classifier: Programming Language :: Python :: 2.6
383 Classifier: Programming Language :: Python :: 2.7
384 Classifier: Programming Language :: Python :: 3
385 Classifier: Programming Language :: Python :: 3.2
386 Classifier: Topic :: Software Development :: Libraries :: Python Modules

No; there is no metadata present to make such a call, so there is nothing pip (or any other tool) could use to determine what version of a package would work with your version of python.

The only option you have is to use a version pin when installing:

pip install -I zope.interface==3.8.0

Note the -I switch there; since you already tried to install the latest version, you may need to ignore any installed version to force the downgrade.

Note that the Trove python version classifiers ( Classifier: Programming Language :: Python :: * ) can not be relied upon for this task; they are set by the developer if they remember to do so, but cannot be updated later on to indicate compatibility with new python versions. They should be seen as a way to help refine searches on PyPI and other package indexes, not as metadata used by installers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM