shapely - ModuleNotFoundError

I have installed shapely using pip.

When I run: pip list I get

Package Version

shapely 2.0.3

but when I try to import it, I get the following:

import shapely
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'shapely'

Any ideas on how to fix this?

How did you install the package -- was it in a virtualenv, or just using pip directly outside a virtualenv? And are you sure you installed it for the same Python version as you're using when you run your code? Each Python version has its own set of installed packages, so if (for example) you're running your code using python3.9, you need to use the corresponding pip3.9 to install packages.

Hi Giles,

I installed the shapely inside my virtualenv using the command pip3.7 install shapely. I've also checked my new virtual environment lib folder and it is listed.

(my-new-virtualenv-marineline) 20:08 ~/marinelineapi (master)$ pip3.7 install shapely
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: shapely in /home/dferrai/.virtualenvs/my-new-virtualenv-marineline/lib/python3.7/site-packages (2.0.3)
Requirement already satisfied: numpy<2,>=1.14 in /home/dferrai/.virtualenvs/my-new-virtualenv-marineline/lib/python3.7/site-packages (from shapely) (1.21.6)

It was working all fine before I migrated to a new environment, what is happening?

Make sure you are running your Python code in the my-new-virtualenv-marineline.