Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'pymongo'

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.

like image 256
user3151858 Avatar asked Apr 05 '14 19:04

user3151858


People also ask

Why is import Pymongo not working?

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.

How install Pymongo Linux?

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.

How do I import MongoClient?

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 );

How do I check my Pymongo version?

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.


1 Answers

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:

  • go to pymongo page
  • download and run installer.
like image 54
Salvador Dali Avatar answered Sep 30 '22 23:09

Salvador Dali