Can't import MongoClient

后端 未结 11 987
时光取名叫无心
时光取名叫无心 2021-01-01 21:18

I am unable to do this:

from pymongo import MongoClient

I get:

>>> import pymongo
>>> from pymongo import         


        
相关标签:
11条回答
  • 2021-01-01 22:03

    I would like to suggest more robust answer:

    pip show pymongo
    

    now see where it direct you and from there simply remove the pymongo directory

    rm -rf <the dir where pymongo lay>/pymongo*
    

    Now, you can safely install pymongo again:

    pip install pymongo
    
    0 讨论(0)
  • 2021-01-01 22:04

    That package is probably outdated or broken. Run sudo apt-get purge python-pymongo, then sudo apt-get install python-pip, then finally sudo pip install pymongo.

    0 讨论(0)
  • 2021-01-01 22:07

    I had the same problem on Ubuntu 16.04.
    This solved my problem:

    sudo apt-get install build-essential python-dev
    
    sudo apt-get install python-pip
    
    sudo pip install pymongo
    
    0 讨论(0)
  • 2021-01-01 22:09

    Python Script

    Try it once, into python script run following statement

    # try.py
    
    import pymongo
    

    If above statement didn't throw any exception then you need to install pymongo-2.4, if existing pymongo verion is 2.3

    Open terminal

    First you need to uninstall old pymongo version

    pip uninstall pymongo
    

    Then use following commands to install pymongo-2.4

    wget http://pypi.python.org/packages/source/p/pymongo/pymongo-2.4.tar.gz
    tar xzf pymongo-2.4.tar.gz
    cd pymongo-2.4
    python setup.py install
    
    0 讨论(0)
  • 2021-01-01 22:11

    yes it's true you need to update use, check the upgrade section says http://api.mongodb.org/python/current/installation.html

       easy_install -U pymongo
    
    0 讨论(0)
提交回复
热议问题