Python 如何安装 PyMongo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26218990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install PyMongo
提问by Anthony Pradal
I am currently trying to install MongoDB driver for Python on my Mac OS X (mavericks).
我目前正在尝试在我的 Mac OS X(小牛)上安装适用于 Python 的 MongoDB 驱动程序。
But when I run
但是当我跑
[ Dsl ~/Documents/python ] sudo easy_install pymongo
I get the following output
我得到以下输出
Searching for pymongo
Best match: pymongo 2.7
Processing pymongo-2.7-py2.7-macosx-10.9-intel.egg
Removing pymongo 2.7rc1 from easy-install.pth file
Adding pymongo 2.7 to easy-install.pth file
Using /Library/Python/2.7/site-packages/pymongo-2.7-py2.7-macosx-10.9-intel.egg
Processing dependencies for pymongo
Finished processing dependencies for pymongo
I try a lot of different commands, but nothing work. How to install pymongo ?
我尝试了很多不同的命令,但没有任何效果。如何安装pymongo?
Thanks for your help
谢谢你的帮助
Edit: When I try to use it in a python script
编辑:当我尝试在 python 脚本中使用它时
#!/usr/bin/env python3
import pymongo
client = MongoClient()
I have this error
我有这个错误
Traceback (most recent call last):
File "./mongo.py", line 2, in <module>
import pymongo
ImportError: No module named 'pymongo'
回答by Jayram
回答by uma
I have same error , and I can fix it following command.
我有同样的错误,我可以按照命令修复它。
sudo pip3 install pymongo
sudo apt-get install python3-pip
Try this. but this command for Ubuntu 14.04 OX.not sure is this work in Max OS X.
尝试这个。但此命令适用于 Ubuntu 14.04 OX。不确定此命令是否适用于 Max OS X。
回答by Yogesh Nikam Patil
For ubuntu , you can try...
sudo pip3 install pymongo
sudo apt-get install python3-pip
It works for me
这个对我有用
回答by D1v3
I'm running python 2.7.12 on Rasbian Jesse. After running:
我在 Rasbian Jesse 上运行 python 2.7.12。运行后:
pip install pymongo
The following command reveals that the pymongo module exists under /usr/local/lib/python2.7/dist-packages/
以下命令显示 pymongo 模块存在于/usr/local/lib/python2.7/dist-packages/ 下
pip show pymongo
One methods that works is to append the sys path with the location of the pymongo module:
一种有效的方法是将 sys 路径附加到 pymongo 模块的位置:
import sys
sys.path.append('/usr/local/lib/python2.7/dist-packages/')
import pymongo
回答by Ash Upadhyay
you can use these commands
你可以使用这些命令
python -m pip install pymongo
To get a specific version of pymongo:
要获取特定版本的 pymongo:
$ python -m pip install pymongo==3.1.1
To upgrade using pip:
使用 pip 升级:
$ python -m pip install --upgrade pymongo
To use easy_install from setuptools do:
要使用 setuptools 中的 easy_install,请执行以下操作:
$ python -m easy_install pymongo
To upgrade do:
要升级,请执行以下操作:
$ python -m easy_install -U pymongo
回答by haosen guan
回答by JERRY
Installing pymongo goes very simple
安装 pymongo 非常简单
Make sure that pythonis installed already in your machine.If not check herefor quick installation.
确保你的机器上已经安装了python。如果没有,请检查这里以进行快速安装。
CentOS:
中央操作系统:
Update using yum
使用 yum 更新
yum -y update
Download the pip using curl:
使用 curl 下载 pip:
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
Install pip command using python
使用python安装pip命令
python get-pip.py
Install pymongo using pip
使用 pip 安装 pymongo
pip install pymongo
回答by Jonathan Bencomo
python3 -m pip install pymongo
worked for me in OS X
在 OS X 中为我工作
回答by Arun Kumar
On Ubuntu 18.04,
在 Ubuntu 18.04 上,
For this, the version of the pip should be less than or the same as 9.0.1.
为此,pip 的版本应小于或等于 9.0.1。
First of all, install the pip for python version 3 from-
首先,从-安装python版本3的pip
sudo apt install python3-pip
and check pip version-
并检查 pip 版本-
pip --version
after that, we have to install build-essential for python-dev
之后,我们必须为 python-dev 安装 build-essential
sudo apt-get install build-essential python-dev
and python setup-tools
和 python 设置工具
sudo apt-get install python-setuptools
And finally, we are able to install pymongo by following command-
最后,我们可以通过以下命令安装 pymongo -
python -m pip install pymongo
It worked for me, may it will work for you too.
它对我有用,也许对你也有用。
回答by Syed
The following worked for me on Windows 10:
以下在 Windows 10 上对我有用:
pip install -- upgrade pymongo

