Reputation: 85
I downloaded and installed mongoDB, ran mongod command on cmd as admin, did install mongodb and pymongo in anaconda however, keep getting this error when I import pymongo
. Searched extensively on the same issue however, it does not really seem to help in my case. Don't understand why and what am I missing. I have python 3.7 on windows.
ModuleNotFoundError Traceback (most recent call last) in ----> 1 import pymongo
ModuleNotFoundError: No module named 'pymongo'
Upvotes: 2
Views: 11269
Reputation: 3811
I installed pymongo today using Anconda.
From Start menu -> Command Prompt(cmd), type below command:
pip install pymongo
Assuming Anaconda 3 folder is in My computer -> C: -> Users -> Uuser name/admin. Right click on My computer -> properties. A tab will open -> Advanced Systems settings-> Advanced tab go to Environmnet Variables at the bottom -> In system variables below, go to path, double click. Click on new and Paste the path of your Anaocnda 3 folder there.
From Start Menu -> Anaconda Prompt, type below command:
conda install pymongo
It will ask you to select yes/no in the middle for packages. You can type Y if it asks and it will proceed.
Go to Anconda Navigator and check whether the pymongo is in installed packages or not after the successful execution of this command. If it is in the installed packages then your work is done.
Go to Anaconda Navigator -> Spyder or Jupyter notebooks and type import pymongo and start coding
`
Upvotes: 0
Reputation: 13106
When using pip install
with anaconda environments, it's imperative that you keep track of which interpreter you are using when installing:
pip -V # might output a different result than
python -m pip -V
The latter is definitely preferred when installing, as you know exactly which interpreter you are using, which will tie it to the correct instance of pip
.
If you have a conda environment
configured, be sure to conda activate <yourenv>
first, this way you can be sure that pip
also installs packages there.
conda activate <yourenv>
python -m pip -V
# /path/to/yourenv/lib/pythonx.x/site-packages
Then, python -m pip install pymongo
should work. Following that, you will want to double check that the env is activated when you run jupyter notebook
as well. If you are in jupyter already, you can run the following to check:
import sys
sys.path[-1]
'/path/to/yourenv/lib/pythonx.x/site-packages'
If this doesn't match where yourenv
should be, then you probably didn't activate the environment. You'll need to stop jupyter, activate, then re-start the notebook.
Upvotes: 3
Reputation: 1801
a common reason for this is that your are using multiple python versions (e.g. 2.X and 3.X) Then it can happen that you install it for a different version than your are actually using.
Check your site-packages
folder if it really contains pymongo
Upvotes: 1