9

I've installed shapely with pip install shapely and importing it as from shapely.geometry import Point. I get this error:

  from shapely.geometry import Point
ModuleNotFoundError: No module named 'shapely'

I'm n MacOS High Sierra. All other installed python libraries work like a charm. I'm new to Python so forgive me in advance. I've read several similar questions (like this one) but none seemed to solve my problem.

Daniela
  • 861
  • 5
  • 11
  • 28
  • Did you `pip install` it to a virtual environment? If so, you need to activate your virtual environment with `source myvenv/bin/activate`. If you haven't set up a virtual environment yet, you might have installed the module in the wrong directory. Make sure to install the module into the main directory of your project. – Jack Moody Mar 16 '19 at 15:23
  • 1
    Where did `pip` install it, and what is the value of `sys.path`? – John Gordon Mar 16 '19 at 15:28
  • You might find this [SO question](https://stackoverflow.com/questions/35017160/how-to-use-virtualenv-with-python) useful, as it provides resources on how to use a virtual environment. Virtual environments help you manage project dependencies and is especially helpful when you have multiple projects. – Jack Moody Mar 16 '19 at 15:32
  • @JohnGordon I installed it in my home directory `/Library/Python/2.7/site-packages/`. How do I check the value of my `sys.path`? – Daniela Mar 16 '19 at 15:41
  • @JackMoody is there a way to install it globally for any projects? How do I activate the env? – Daniela Mar 16 '19 at 15:44
  • @Daniela normally you don't want to install a module globally, because you will probably use multiple versions of the same module in between your projects. If you really do want to install it globally, you can use `sudo` as explained [here](https://stackoverflow.com/questions/36936212/how-do-i-install-a-pip-package-globally-instead-of-locally/36937521). However, I would strongly encourage using a virtual environment if you plan on having multiple projects in the future. – Jack Moody Mar 16 '19 at 15:46
  • @JackMoody Thank you. I'll look into it. – Daniela Mar 16 '19 at 16:20
  • `import sys; print (sys.path)` – John Gordon Mar 16 '19 at 20:01

2 Answers2

9

Run the following command in activated virtualenv:

pip install shapely
yugandhara
  • 91
  • 1
  • 4
0

I tried this command and it was efficient.

conda install -c conda-forge shapely