Shapely installation with pip

Question:

I just created my virtual environment inside my project with the following command: python -m virtualenv venv', and I activated it. I tried to install files from the requirements.txt file with the command pip install -r requirements.txt’. I tried in both cases with venv on or of. In the requirements file there are some normal packages and a couple of private ones. When it is time to install the last private package, the following errors appear:


Collecting Shapely==1.7.1
  Using cached Shapely-1.7.1.tar.gz (383 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:UsersmpossAppDataLocalTemppip-install-5x5ouymyshapely_bf50a01d45e7491aabfe1d2febea9725setup.py", line 85, in <module>
          from shapely._buildcfg import geos_version_string, geos_version, 
        File "C:UsersmpossAppDataLocalTemppip-install-5x5ouymyshapely_bf50a01d45e7491aabfe1d2febea9725shapely_buildcfg.py", line 205, in <module>
          lgeos = CDLL("geos_c.dll")
        File "C:Program FilesPython310libctypes__init__.py", line 374, in __init__
          self._handle = _dlopen(self._name, mode)
      FileNotFoundError: Could not find module 'geos_c.dll' (or one of its dependencies). Try using the full path with constructor syntax.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

So the error occurs while installing shapely. Reading all the requirements.txt files, there is never someone with shapely in it. But maybe other packages need it. I read a lot of StackOverflow answers where people tell me to use conda instead of pip, but I can’t because I need to work in this virtual environment

How can I fix this problem? Please, if you can, help me.

Asked By: Poss

||

Answers:

Try downloading the geos_c.dll file from here: https://www.dll-files.com/geos_c.dll.html and then extract the zip file in your pc system directory (e.g. C:WindowsSystem32 for windows from XP on).
Add then the system directory to the path and install shapely 1.6.3.
It worked for me.

Answered By: Dario Sangiovanni

I had the same problem on Ubuntu, the problem was solve by running the command:

sudo apt-get install libgeos-c1v5
Answered By: Eduardo Morais
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.