热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

pymongo:ImportError:没有名为pymongo的模块

如何解决《pymongo:ImportError:没有名为pymongo的模块》经验,为你挑选了1个好方法。

我成功安装了pymongo使用 pip3

Aleeshas-MacBook-Air:project 2 aleesha$ sudo pip3 install pymongo
The directory '/Users/aleesha/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/aleesha/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pymongo
  Downloading pymongo-3.4.0-cp35-cp35m-macosx_10_6_intel.whl (294kB)
    100% |????????????????????????????????| 296kB 730kB/s 
Installing collected packages: pymongo
Successfully installed pymongo-3.4.0
Aleeshas-MacBook-Air:project 2 aleesha$

然后我在python中编写了一个写入MongoDB的测试脚本.但是当我执行它时,我收到以下错误:

Aleeshas-MacBook-Air:project 2 aleesha$ python pythonScript.py 
Traceback (most recent call last):
  File "pythonScript.py", line 5, in 
    from pymongo import MongoClient
ImportError: No module named pymongo
Aleeshas-MacBook-Air:project 2 aleesha$

Python版本: Python 3.5.2

这就是路径的样子:

 >>> import sys
    >>> sys.path
    ['', '/Users/aleesha/Documents', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages']
>>> sys.version
'3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
>>> 

在谷歌上搜索.在stackoverflow上找到这个问题:ImportError:没有名为'pymongo'的模块然后指向stackoverflow上的另一个页面:无法导入pymongo ubuntu

sudo pip uninstall pymOngo==> Succesfully uninstalled
sudo pip uninstall bson ==> Cannot uninstall requirement bson, not installed
sudo apt-get remove python-bson ==> sudo: apt-get: command not found
sudo apt-get remove python-gridfs    # not sure if it's necessary ==> sudo: apt-get: command not found
sudo pip install pymongo -U ==> successfully installed pymongo

然而即使在此之后,我也面临同样的问题.我无法导入pymongo模块.

编辑:我正在尝试更多的事情来解决这个问题.使用IDLE我可以导入pymongo并轻松地将记录插入MongoDB.

>>> from pymongo import MongoClient
>>> client = MongoClient()
>>> db = client.kmp
>>> db.KMP_DATA.insert_one({"seq" : 1,"data" : "ABCD"})

>>> 

但是我仍然无法从python脚本导入它.



1> A. Jesse Jir..:

"pip"或"pip3"与"python"或"python3"的环境不同是一个常见问题.确保使用与运行相同的环境进行安装:

python -m pip install pymongo

要么:

python3 -m pip install pymongo


推荐阅读
author-avatar
44要和自己交个朋友
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有