Search code examples
pythonpipenvshapely

How to cross-platform install a package pipenv, method depending on the platform?


I'm trying to install the Shapely package to a cross-platform project using pipenv. However, on Windows, shapely can't be installed using a simple pipenv install shapely, it throws errors for a missing dependent dll. For this purpose, there is a pre-built wheel available from the famous unofficial package wheels by Christoph Gohlke:

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

[packages]
shapely = {file = "https://download.lfd.uci.edu/pythonlibs/n5jyqt7p/Shapely-1.6.4.post2-cp37-cp37m-win_amd64.whl", sys_platform = "== 'win32'"}

[dev-packages]

[requires]
python_version = "3.7"

This wheel is perfect for Windows, but only for Windows. So how do I specify in a Pipfile that, only if the platform is linux, it can simply pipenv install shapely as:

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

[packages]
shapely = "==1.6.4.post2"

[dev-packages]

[requires]
python_version = "3.7"

or is this not possible using pipenv? Or do I hack together a Pipfile.Windows file that my unfortunate Windows colleague can rename to Pipfile?

Many thanks for any pointers.


Solution

  • wheel distribution is ok with linux as well, sorry, don't know you linux distro, but you can try this:

    [packages]
    # for linux
    shapely = {file = "https://files.pythonhosted.org/packages/97/36/1af447160f713d72f35dd7e749788367b7a13285c4af2fbd675128aa4e99/Shapely-1.6.4.post2-cp37-cp37m-manylinux1_x86_64.whl", platform_system="Linux"}
    
    # for windows
    shapely_win = {file = "https://download.lfd.uci.edu/pythonlibs/n5jyqt7p/Shapely-1.6.4.post2-cp37-cp37m-win_amd64.whl", platform_system="Windows"}
    

    shapely_win name doesn't affect package installation