Carlo
Carlo

Reputation: 443

No module named 'pymongo' despite installation

When I run import pymongo I obtain ModuleNotFoundError: No module named 'pymongo' despite !pip install pymongo returning Requirement already up-to-date: pymongo in /usr/local/lib/python2.7/site-packages (3.8.0)

I'm using python notebook with Python version 3.7.1 and pymongo version 3.8.0

I tried unistal and re-install pymongo, with no result.

None of the suggestions I've seen on similar questions seem to work (or I was unable to understand how to apply them).

Upvotes: 0

Views: 2665

Answers (1)

zachdj
zachdj

Reputation: 369

Notice that pymongo got installed in /usr/local/lib/python2.7, but you mentioned that you're running iPython with the Python 3.7 interpreter.

I'm guessing you have two or more Python installations on your system (2.7 and 3.7) and 2.7 is the default.

An immediate fix for your problem is to install pymongo for the Python 3.7 interpreter. The command depends on where you have Python 3.7 installed, but it would be something like

/usr/local/lib/python3.7/pip install pymongo

But you should really, really be using virtual environments to separate your Python installations. Use something like pipenv to create a virtual environment, install pymongo inside the environment, and configure your notebook to use the environment instead of your global Python installation.

Upvotes: 2

Related Questions