Skip to content
Advertisement

How does pipenv determine package versions to install?

I have a Pipenv file which looks something like this

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
antlr4-python3-runtime = "4.8"
numpy = "1.19.3"
...

However, when I create the environment by running pipenv install, the versions antlr4-python3-runtime==4.9.2 and numpy==1.21.2 are installed instead. If I modify the Pipfile in the following way:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
antlr4-python3-runtime = "==4.8"
numpy = "==1.19.3"
...

Then it installs the correct versions. I am a bit confused on what happens when you specify a version with "4.8" vs "==4.8", because it seems like the former doesn’t work. How is the former different from not specifying any version at all?

Advertisement

Answer

Usually you will want to follow the guides specified in the manual here.

You should not also be editing the Pipfile manually, except for adding new indices or configurations. Whenever you install a package you will want to use pipenv install ... as shown in the link above.

The doubt you have is a matter of editing dependencies manually in the Pipfile. If you use pipenv install you will need to rely on the correct markers defined here

IMO it is unfortunate that pipenv tries to solve the markers more than it should. In fact you can abuse the syntax when installing and it still works, which can potentially cause several problems to be hidden from developers.

As as example, suppose you have a package published as my_awesome_package with versions 0.9, 1.0 and 1.1 available at pypi. You can still install a package using:

pipenv install my_awesome_package>>>>1

Or if you add

my_awesome_package-lib = ">>foo>>bar>>1"

This is an exaggerated example, but still, IMO should not be valid as >>>> should not be considered a marker. So keep in mind that pipenv will do some kind of “best effort” to solve the package even if your syntax is strange.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement