I have a problem running pymongo
on Win 7 (64) with Python 3.4, mongodb 4.2.10. The error output is as follows:
import pymongo ImportError: No module named 'pymongo'
The code is pretty simple:
import pymongo from pymongo import MongoClient client=MongoClient() db=client.test_db dict={'A':[1,2,3,4,5,6]} db.test_collection.insert(dict) to_print=db.test_collection.find() print(to_print)
I tried already re-installing Python and MongoDB - did not help. It works when I do it manually in cmd, i.e. mongod.exe
and mongo.exe
work fine. It appears there is problem with pymongo
, but I don't know how to fix it.
The Python error "ModuleNotFoundError: No module named 'pymongo'" occurs for multiple reasons: Not having the pymongo package installed by running pip install pymongo . Installing the package in a different Python version than the one you're using. Installing the package globally and not in your virtual environment.
Install the PyMongo library using Python's PIP package manager. You'll need to install the MongoDB driver for Python on the machine or server where MongoDB is running. Use the pip3 (or just pip for Python 2) package manager to install the MongoDB Python driver.
You can explicitly specify the hostname to connect to a MongoDB instance running on the specified host on port 27017 : MongoClient mongoClient = new MongoClient( "host1" ); You can explicitly specify the hostname and the port: MongoClient mongoClient = new MongoClient( "host1" , 27017 );
The result of that command is: pymongo==3.0, none of them above! @Egzona So, that's the version of pymongo you've installed. You can force to install it by pip install pymongo==2.7 , sudo maybe required.
All you need is to actually install pymongo
(currently you just have mongo and python, but they do not know how to speak with each other). This page is telling you exactly what to do:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With