Shapely: Can't package with pipenv and cx_freeze: OSError: Could not find lib geos_c.dll or load any of its variants []

Created on 16 Sep 2020  ·  3Comments  ·  Source: Toblerity/Shapely

Expected behavior and actual behavior.

When freezing my python3.8 program into an msi using cx_freeze, the msi works on the computer it was built on but not on other hosts.
The error message is: OSError: Could not find lib geos_c.dll or load any of its variants [].

Steps to reproduce the problem.

Pipfile:

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

[packages]
cx_Freeze = "==6.2"
shapely = "==1.7.1"

[requires]
python_version = "3.8"

[scripts]
build = "python setup.py bdist_msi"

setup.py:

from cx_Freeze import setup, Executable

if __name__ == "__main__":
    APP = Executable(
        script="test.py",
        base=None,
        targetName="test",  # executable name avaiable in cli after installation
    )

    setup(
        name="test",
        options={
            "build_exe": {},
            "bdist_msi": {
                "add_to_path": True,
                "all_users": True,  # require admin rights
            },
        },
        executables=[APP],
    )

test.py:

from shapely.geometry import LineString

pallet_line_string = LineString(
    [
        (0, 0),
        (10, 0),
        (10, 20),
        (0, 20),
        (0, 0),
    ]
)
print(pallet_line_string)

Operating system

Windows 10

Shapely version and provenance

1.7.1 installed from PyPI using pipenv

invalid

Most helpful comment

The error message was misleading: the geos_c.dll was indeed found, but it’s dependencies we’re not. I had to install Microsoft’s VC Redistributables to get it to work.
Thanks!

All 3 comments

@ypicard I'm sorry about the trouble, but this is not a shapely issue. You must work out how to include a compatible geos_c.dll in your bundle. Here is how we do it for shapely wheels built on appveyor: https://github.com/Toblerity/Shapely/blob/maint-1.7/appveyor.yml#L84.

The thing is, the dlls are already packaged correctly. I can find them in the installation directory of my program (C:\Program Files (x86)\my_program\lib\shapely\DLLs). They seem to be correctly bundled.
The problem is that shapely can't load them correctly. I printed the path at geos.py:166 and both egg_dlls and wininst_dlls look correct.
What is happening ?

The error message was misleading: the geos_c.dll was indeed found, but it’s dependencies we’re not. I had to install Microsoft’s VC Redistributables to get it to work.
Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benediktbrandt picture benediktbrandt  ·  3Comments

romainfontaine picture romainfontaine  ·  5Comments

LostFan123 picture LostFan123  ·  3Comments

jGaboardi picture jGaboardi  ·  5Comments

akadouri picture akadouri  ·  4Comments