Search code examples
python-3.xvisual-studio-2017packageshapely

Cannot install shapely on VS 2017


When trying to install the 'shapely' Python package, on VS 2017 15.6.6, Windows 7 64b, I get this error message

        File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

I believe, I have the same problem than here

The accepted solution on that question advices to run this

python -m pip install Shapely-1.5.17-cp36-cp36m-win_amd64.whl

But that shapely package here has changed to

Shapely, a package for creation, manipulation, and analysis of planar geometry objects based on GEOS.

    Shapely‑1.6.4.post1‑cp27‑cp27m‑win32.whl
    Shapely‑1.6.4.post1‑cp27‑cp27m‑win_amd64.whl
    Shapely‑1.6.4.post1‑cp34‑cp34m‑win32.whl
    Shapely‑1.6.4.post1‑cp34‑cp34m‑win_amd64.whl
    Shapely‑1.6.4.post1‑cp35‑cp35m‑win32.whl
    Shapely‑1.6.4.post1‑cp35‑cp35m‑win_amd64.whl
    Shapely‑1.6.4.post1‑cp36‑cp36m‑win32.whl
    Shapely‑1.6.4.post1‑cp36‑cp36m‑win_amd64.whl
    Shapely‑1.6.4.post1‑cp37‑cp37m‑win32.whl
    Shapely‑1.6.4.post1‑cp37‑cp37m‑win_amd64.whl

The questions are:

  • Which one of those strings do I need to use in the command?

  • Since I already clicked on

    1.6.4.post1

(screen capture)

Should I try to install an older version, supposedly Shapely-1.5.17?

  • Where I'm supposed to enter the commands, on the Anaconda interactive window?

(Screen capture)


Solution

  • My guess is that something is wrong with shapely and it's only available in conda environments and not in PyPI. Visual Studio however has to be made aware of conda before it can install shapely: Visual Studio is using "pip install shapely" when what you want is "conda install shapely". Here's how I solved the problem.

    1. Update Visual Studio 2017 to 15.7.4. I was at 15.7.3 (?) and that didn't work: only at version 15.7.4 did I see the correct python package option (i.e. step 5 below).
    2. Open the Python Environments Window (View -> Other Windows -> Python Environments).
    3. Make sure that the Python Environments window is very wide (I've got it at about 60% of my screen width).
    4. If you don't see an "Anaconda" entry, go to Windows search, find and open Visual Studio Installer. Use the installer to install the appropriate version of Anaconda.
    5. With Anaconda installed, go back to the Python Environments window and click on "Anaconda" on the left side of the window. In the middle of the window you should see a Packages (Conda) entry. Select that entry.
    6. On the right side of the Python Environments window, there's a text box; enter "shapely" there. As you type, you should see a line like "Run command: conda install shapely". Click that line and shapely should install.
    7. In your project's properties click on the General tab, then change the Interpreter to the version of Anaconda you just installed.