简体   繁体   中英

Error importing Polygon from shapely.geometry.polygon

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.

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 with below one, it solved the issue for me (Windows 10):

conda install -c conda-forge shapely

shapely package docs

Try this:

from shapely.geometry import Polygon

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM