Error importing Polygon from shapely.geometry.polygon

爷,独闯天下 提交于 2020-01-13 18:40:33

问题


In my Anaconda 2.2 64bit with Python 3.4.3 the following line works well:

import shapely

But the following line:

from shapely.geometry.polygon import Polygon

returns the following error:

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

What am I missing?

EDIT

I tried with iNotebook, idle.exe and Eclipse. They all use Anaconda (the only Python installation on my computer) and they all show the same error.

If I type from shapely.geometry import Polygon in Eclipse, then I click on Polygon, then I press F3, Eclipse is able to open the module C:\Anaconda3\Lib\site-packages\shapely\geometry\polygon.py. So Eclipse is able to find it, but the execution fails.

EDIT 2

I just tried the same import on another computer with similar configuration and it works. The "only" difference between the two computers is that one has Windows 7 (it works) and one has Windows 8 (it doesn't).

I installed Anaconda and a few packages in both the computers following the same old checklist. The computer with Windows 8 can see the package from Eclipse, but can't import it.


回答1:


I had a similar problem and it was due to the way that I improperly installed shapely (although this was on a Windows 7 machine, not Windows 8). For the initial install under which I couldn't import the geometry sub-module I installed shapely with the command:

pip install shapely

However after reading the documentation here more closely I saw that for Windows an executable installer needed to be used. That installer is a wheel file that needs to be launched by pip as well. So I uninstalled the first version of shapely with:

pip uninstall shapely

Then I launched the installer via the wheel file like this:

pip install your/file/path/Shapely‑1.5.9‑cp27‑none‑win32.whl

Note that you must download the wheel that matches the specs of the version of python that your applying the package to. I have 32-bit (win32) python 2.7 (p27) so the package above was the correct one. Note that the reference to 32 or 64 bit in the file name refers to the version of python, not to the version of windows.




回答2:


Try this:

from shapely.geometry import Polygon

That's how the docs list it: http://toblerity.org/shapely/manual.html#polygons




回答3:


Don't use anything but Python version 3.7. Download it now!

Then go to PyCharm (that's what I'm using) and open it, then download the file for your specific version (from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely) mine is Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl (this is respectively version 3.7 (37) and Windows (64) as seen above)

Now with your newly downloaded file, copy and paste it into where you are working from in PyCharm's folder location. For me this is: C:\Users\lewis\PycharmProjects\Project1\NewProject

Then you should see the newly copied file in PyCharm itself as well as where you put it.

Now right click the file in PyCharm Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl and click OPEN IN TERMINAL then type:

pip install Shapely-1.6.4.post1-cp37-cp37m-win_amd64.whl

It should say "successful".

Then go into your working area and type:

from shapely.geometry import point

Run it. It should now work for all!

Be in mind that this will ONLY allow for the importing of Shapely in this one environment. So you'll have to copy the Shapely file into new folder locations if you use in other places.

Specs:
Be in mind I am working with a Windows 10, Python interpreter version 37, PyCharm, Virutalenv environment type. Also, make sure in the settings you are indeed in the Python 37 interpreter and not in a conda environment.



来源:https://stackoverflow.com/questions/29904248/error-importing-polygon-from-shapely-geometry-polygon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!