Platform-specific requirements.txt in PyCharm? Different version requirements on different platforms?

Viewed 46

For reasons I won't go into here, I've got a Python application which uses PyQt5.15.6 when on Windows, but PyQt5.14.2 on MacOS. The fact it's PyQt isn't important, this is a question about requirements.txt and PyCharm.

In my requirements.txt, I've got the following:

PyQt5==5.14.2  # platform_system == "Darwin"
PyQt5==5.15.6  # platform_system == "Windows"

As far as I've seen, that ought to tell the environment to install version 5.14.2 if on a Mac, or version 5.15.6 if on Windows.

However, PyCharm doesn't seem to understand this. It wants to install both versions (?!) and is repeatedly reminding me that requirements.txt isn't fulfilled because version 5.14.2 isn't installed, when in fact it's fine because 5.15.6 is installed.

Is there anything I can do within requirements.txt, or in PyCharm's options, to get PyCharm to understand that this is OK? Or do I need to split my requirements.txt in two?

Screenshot of requirements.txt in PyCharm highlighting issues that aren't issues

1 Answers

Operating system verification occurs line by line in requirements.txt.

For that you have to put after the version of the package platform_system == SO.

In the printscreen you sent, the verification does not occur because of the comment (#). Remove the '#', you'll likely get the solution you want.

PyQt5==5.14.2; platform_system == "Darwin"
PyQt5==5.15.6; platform_system == "Windows"

Hope this helps

Related