ERROR: Could not find a version that satisfies the requirement my-package==2021.4.* (from versions: 0.0.2, 2021.4.1.dev44+gd452819a91.d20210528, 2021.5.26)
This looks weird, right? Why doesn't the second one in the list match???
~=2021.4.1 doesn't work either. =~2021.4 installs 2021.5.26
The only way I found for it to work is to spell it out completely: ==2021.4.1.dev44+gd452819a91.d20210528
Why don't the match operators work?
By default, pip ignores pre-release and development versions. Per the pip documentation on pre-release versions:
Starting with v1.4, pip will only install stable versions as specified by pre-releases by default. If a version cannot be parsed as a compliant PEP 440 version then it is assumed to be a pre-release.
If a Requirement specifier includes a pre-release or development version (e.g. >=0.0.dev0) then pip will allow pre-release and development versions for that requirement. This does not include the != flag.
If you want pip to also match pre-release and development version against the version specifier, you can pass the --pre flag when invoking pip install:
Related
I want to install a specific version of PyTorch (inside a Dockerfile) to handle modern GPUs: 1.8.1+cu111. Please note the local version identifier. I then install (both via pip) a library that requests torch>=1.8.1 as a dependency. For some reason, this uninstalls my 1.8.1+cu111 and replaces it with vanilla 1.10.0, despite the custom version with "local version specifier" should be taken as valid as PEP 0440 says (...local version labels MUST be ignored entirely when checking...) and it's what is happening normally, e.g. here or even for me when I try to re-install PyTorch by hand:
pip install "torch>=1.8.1"
Requirement already satisfied: torch>=1.8.1 in /usr/local/lib/python3.7/dist-packages (1.8.1+cu111)
But no, when I install my library, I get this:
...
Collecting torch>=1.8.1
Using cached torch-1.10.0-cp37-cp37m-manylinux1_x86_64.whl (881.9 MB)
...
Installing collected packages: torch,...
Attempting uninstall: torch
Found existing installation: torch 1.8.1+cu111
Uninstalling torch-1.8.1+cu111:
Successfully uninstalled torch-1.8.1+cu111
How can I make it keep the pre-installed 1.8.1+cu111?
In the PEP040, you have above:
When multiple candidate versions match a version specifier, the preferred version SHOULD be the latest version as determined by the consistent ordering defined by the standard Version scheme. Whether or not pre-releases are considered as candidate versions SHOULD be handled as described in Handling of pre-releases.
I think this because you are using an inclusive specifier where local version identifiers are NOT permitted
Can you specify the exact version with pip install "torch==1.8.1+cu111" ? Maybe only 1.8.1 works.
Imagine you have published two pre-releases:
package 0.0.1.dev0
package 0.0.2.dev0
My install_requires section in setup.py states:
[
'package>=0.0.2,<1.0.0'
]
Now, when i run pip install . --upgrade --pre I get an error:
ERROR: Could not find a version that satisfies the requirement package<1.0.0,>=0.0.2 (from versions: 0.0.1.dev0, 0.0.2.dev0)
ERROR: No matching distribution found for package<1.0.0,>=0.0.2
What am I doing wrong? Isn't the --pre flag supposed to tell pip to match pre-release versions?
Summary
The pip --pre option directs pip to include potential matching pre-release and development versions, but it does not change the semantics of version matching.
Since pre-release 0.0.2.dev0 is older than stable release 0.0.2, pip correctly reports an error when searching for a package that is at least as new as stable release 0.0.2.
Explanation
The key point of confusion is around the pip --pre option, which is documented as:
--pre
Include pre-release and development versions. By default, pip only finds stable versions.
The premise of the question is that the --pre option should change the package-version-matching semantics such that pre-release version suffixes would be ignored when matching against stable versions.
To further clarify, consider the compatible release operator ~=. PEP 440 section Compatible release, states in part:
For a given release identifier V.N, the compatible release clause is approximately equivalent to the pair of comparison clauses:
>= V.N, == V.*
...
If a pre-release, post-release or developmental release is named in a compatible release clause as V.N.suffix, then the suffix is ignored when determining the required prefix match:
~= 2.2.post3
= 2.2.post3, == 2.*
~= 1.4.5a4
= 1.4.5a4, == 1.4.*
This example makes it clear that the suffix is ignored.
The following requirement does not match 0.0.2.dev0:
install_requires=['package~=0.0.2'] # ERROR: ResolutionImpossible
Whereas this example does match stable release 0.0.2:
install_requires=['package~=0.0.2.dev0'] # OK - suffix ignored
I have a custom pypi server, that I am installing files from. I attempt to upgrade from version 0.0.1 to a newer version of my own custom module. It is not detecting the later version. When I do a pip install 'mymodule>=17' I see:
Could not find a version that satisfies the requirement mymodule>=17
(from versions: 17.0828.222133-e1e0fd9, 17.0828.222305-e1e0fd9,
17.830.210154-e1e0fd9, 0.0.1)
Notice the versions show up, but it will never detect the 17.X versions with the git sha on the end. Ideas? Why would this be?
Due to the hyphen, 17.0828.222133-e1e0fd9 and the like are not valid version specifiers as defined in PEP 440. As a result, they are treated as "legacy version" strings by pip's internals and are sorted less than all valid version strings. Hence, as far as pip is concerned, these versions are not greater than 17.
When I specify version requirement with upper and lower bound, it fails to satisfy if there is version which contains letters exists.
pip install 'Django>=1.8,<1.9' --upgrade
I expect it will install version 1.8.11 as it is current newest 1.8.x version. It works in my computer. However it installs 1.9rc1 in another machine (OpenShift), while 1.9rc1 is not in range [1.8, 1.9) IMHO.
How does pip version comparison works? How to specify version requirement [1.8, 1.9) correctly?
Thanks a lot
My project Pyrr was previously using versions that were datestamps.
The last datestamped version was:
version='20130321'
I want to move to a proper major.minor.micro format.
I've updated a new package to PyPi in this format.
version='0.1.0'
When I pip install pyrr I still get the 20130321 version.
$ yolk -V pyrr
pyrr 0.1.0
$ pip install pyrr
Downloading/unpacking pyrr
Downloading pyrr-20130321.tar.gz
<snip>
PyPi has the over versions marked as hidden and the 0.1.0 as the only version not marked hidden.
What do I have to do to get pip / pypi to download the 0.1.0 version instead of the older datestamp versions?
20130321 is the major version, which is obviously higher than 0, therefor version 20130321 is considered the latest version.
The easiest way to fix this would be to delete the outdated version using the webinterface.
If the older versions should still exist, you could download them and reupload them using a newer version. e.g. 0.0.20130321.
If people depend on your package without a version, they wouldn't notice the new versioning system.
If people do depend on a specific version, they would have to change their version dependency. This could be considered annoying, but it is inevitable and it's a small change for them.