简体   繁体   中英

Not able to resolve ModuleNotFoundError: No module named 'pymongo'

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'

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 .

Activate

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.

a common reason for this is that your are using multiple python versions (eg 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

I installed pymongo today using Anconda.

  1. Go to Start-> Anconda Navigator. Click on Environments. Search for pymongo in installed packages.
  2. If pymongo doesnt exist in installed packages, do below:
  3. From Start menu -> Command Prompt(cmd) , type below command:

      pip install pymongo 
  4. 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.

  5. 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.

  6. 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.

  7. Go to Anaconda Navigator -> Spyder or Jupyter notebooks and type import pymongo and start coding

`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM