Error importing Polygon from shapely.geometry.polygon

寵の児 提交于 2019-12-05 19:33:59

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.

Try this:

from shapely.geometry import Polygon

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

Alex

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.

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