0

Hello~when I import specific package from shapely, input the follow

from shapely.geometry import Point, Polygon
from shapely.geometry.polygon import LinearRing, LineString

but seem to be failed to load them, The feedback was following:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-4-452b9f8a12ab> in <module>
      1 #Shapely Library
----> 2 from shapely.geometry import Point, Polygon
      3 from shapely.geometry.polygon import LinearRing, LineString

C:\ProgramData\Anaconda3\lib\site-packages\shapely\geometry\__init__.py in <module>
      2 """
      3 
----> 4 from .base import CAP_STYLE, JOIN_STYLE
      5 from .geo import box, shape, asShape, mapping
      6 from .point import Point, asPoint

C:\ProgramData\Anaconda3\lib\site-packages\shapely\geometry\base.py in <module>
     16 
     17 from shapely.affinity import affine_transform
---> 18 from shapely.coords import CoordinateSequence
     19 from shapely.errors import WKBReadingError, WKTReadingError
     20 from shapely.geos import WKBWriter, WKTWriter

C:\ProgramData\Anaconda3\lib\site-packages\shapely\coords.py in <module>
      6 from ctypes import byref, c_double, c_uint
      7 
----> 8 from shapely.geos import lgeos
      9 from shapely.topology import Validating
     10 

C:\ProgramData\Anaconda3\lib\site-packages\shapely\geos.py in <module>
    143     if os.getenv('CONDA_PREFIX', ''):
    144         # conda package.
--> 145         _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
    146     else:
    147         try:

C:\ProgramData\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    362 
    363         if handle is None:
--> 364             self._handle = _dlopen(self._name, mode)
    365         else:
    366             self._handle = handle

OSError: [WinError 126] The specified module could not be found

then I go to the due file location, the py documents could not be open.

Could you help me import the pakage?

Further tries but didn't work:

α 1. download the OSGeo4W64 into C:\

  1. create a folder bin
  2. manually copied geos_c.dll from shapely\DLL into the folder

β reinstall shapely package via

pip uninstall shapely

pip install shapely

obtained latest version 1.7, when I look into the package modules' code, they were complete.

γ submitted a issue on github -Toblerity/Shapely but hinted we should submit it on conda page.

brutal
  • 1
  • 3
  • there is a github issue with [this comment](https://github.com/Toblerity/Shapely/issues/343#issuecomment-393510213), try it and let us know – Azat Ibrakov Apr 26 '20 at 07:19
  • also [this thread](https://stackoverflow.com/questions/13144158/python-geos-and-shapely-on-windows-64) may be related – Azat Ibrakov Apr 26 '20 at 07:20
  • thank you @AzatIbrakov ,I have pip install geos, installed OSGeo4W from official website and added environment variables but still failed. – brutal Apr 26 '20 at 07:57
  • 1
    Does this answer your question? [Install Shapely: OSError: \[WinError 126\] The specified module could not be found](https://stackoverflow.com/questions/44398265/install-shapely-oserror-winerror-126-the-specified-module-could-not-be-found) – Georgy Apr 26 '20 at 10:40
  • Debug your code, determine the path, where geos_c.dll should be located (os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll') - line 145 in the C:\ProgramData\Anaconda3\lib\site-packages\shapely\geos.py) and copy it manually there. – Andrew Apr 26 '20 at 10:40
  • @Georgy thanks but not, the package was reinstalled for times, now 1.7version fits the os best – brutal Apr 26 '20 at 12:39
  • @Andrew thx, I spot the 'geos_c.dll' and 'geos.dll' was in this file, _C:\ProgramData\Anaconda3\Lib\site-packages\shapely\DLLs_ and drag the geos_c.dll into 'geos.py' but the cmd burst and closed itself...and still doesn't work – brutal Apr 26 '20 at 12:45
  • If none of the solutions worked from the links above, the only thing *I* can suggest is to [create an issue](https://github.com/Toblerity/Shapely/issues?q=is%3Aissue) on their GitHub page. And if you'll solve this problem in the end, please, post the solution on the duplicate link above. This will help future visitors since the questions about "WinError 126" are the most frequent under Shapely tag. – Georgy Apr 26 '20 at 12:53
  • maybe we could find something from line364 _dlopen(self._name, mode)? – brutal Apr 26 '20 at 13:04
  • @brutal, Hmm, for the "standard" Python installation os.path.join(...) results in C:\Program Files\Python38\Library\bin\geos_c.dll. Please show your sys.prefix and the path of your dll location? – Andrew Apr 26 '20 at 17:10
  • @Andrew my sys.prefix was 'C:\\ProgramData\\Anaconda3' and dll location was 'C:\ProgramData\Anaconda3\Lib\site-packages\shapely\DLLs' – brutal Apr 27 '20 at 07:24
  • @brutal. If your sys.prefix is C:\ProgramData\Anaconda3, shapely tries to find dll(s) in the directory C:\ProgramData\Anaconda3\Library\bin according to your stack trace. Did you copied it/them there? If yes, but error still exists, use depends.exe to find dependent dll(s) which may be still missed. – Andrew Apr 27 '20 at 07:46
  • @brutal: see also here: https://github.com/Toblerity/Shapely/pull/843 Additionally, I have some old project with shapely, no problems with python from python.org. – Andrew Apr 27 '20 at 08:50

0 Answers0