Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify multiple sys_platforms with Pipenv

I'm trying to use Pipenv to specify a particular package to only install on Linux or Mac. According to pep496, I should be able to do something like this in a requirements file.

unicon; sys_platform == 'linux' or sys_platform  == 'darwin'

This is what the equivalent Pipfile section looks like.

[packages]
requests = "*"
unicon = {version = "*", sys_platform = "== 'linux' or == 'darwin'"}

This creates a Pipfile.lock without error but also without any marker information. When installing from windows it should just skip trying to install unicorn but it doesn't and there isn't a version of unicorn for windows so I get an install error.

I realize I could probably make things easy and just do sys_platform = "!= 'win32'" but I was wanting to be explicit about the platforms.

Is there any kind of in ['linux', 'darwin'] way to do this?

like image 268
Gabriel G. Avatar asked Dec 10 '18 17:12

Gabriel G.


People also ask

Does Pipenv install dependencies?

With Pipenv and the Pipfile, you present to others a standardized way to install project dependencies and testing and development requirements. Anyone who has a copy of your Pipfile can recreate your environment with the following command.

Is Pipenv better than pip?

While pip can install Python packages, Pipenv is recommended as it's a higher-level tool that simplifies dependency management for common use cases. This does a user installation to prevent breaking any system-wide packages.

How do I add a package to Pipenv?

Set up a new project with PipenvOpen a console in your project directory and type pipenv install <package_name> to install a package for the project. To specify that the package is for development, use the -d flag. You can use pip syntax to denote a specific version of a package (e.g., black==13.0b1 ).

What does Pipenv lock do?

$ pipenv lock is used to create a Pipfile. lock , which declares all dependencies (and sub-dependencies) of your project, their latest available versions, and the current hashes for the downloaded files. This ensures repeatable, and most importantly deterministic, builds.


2 Answers

Using markers instead of sys_platform, the syntax from your PEP 496 example can be used to specify multiple platforms in Pipfile:

[packages]
unicon = {version = "*", markers = "sys_platform == 'linux' or sys_platform == 'darwin'"}
like image 95
Jonathan Feenstra Avatar answered Oct 03 '22 13:10

Jonathan Feenstra


I found a way to not install pypiwin32 on Linux. I had to specify another dependency not listed in my requirements.txt: pywin32

Additionally, I used the os_name marker :

pypiwin32 = { version = "==223",  os_name = "=='nt'"}
pywin32 = {version = "*",   os_name = "=='nt'"}

And the two packages need the markers in Pipfile:

 "markers": "os_name == 'nt'",

The installation using pipenv now works.

like image 20
Philippe T. Avatar answered Oct 03 '22 12:10

Philippe T.