Python pymongo虽然已安装,但仍然存在恐怖

Python pymongo虽然已安装,但仍然存在恐怖,python,pip,pymongo,Python,Pip,Pymongo,我试图让pymongo在我们的linux服务器上运行,但是有些东西失败了,但我不知道是什么 我在本地计算机(OsX)上运行相同的设置 我使用pip安装了pymongo,建议如下: $ sudo pip install pymongo Downloading/unpacking pymongo Downloading pymongo-3.1.tar.gz (462kB): 462kB downloaded Running setup.py (path:/tmp/pip_build_root/py

我试图让pymongo在我们的linux服务器上运行,但是有些东西失败了,但我不知道是什么

我在本地计算机(OsX)上运行相同的设置

我使用pip安装了pymongo,建议如下:

$ sudo pip install pymongo

Downloading/unpacking pymongo
Downloading pymongo-3.1.tar.gz (462kB): 462kB downloaded
Running setup.py (path:/tmp/pip_build_root/pymongo/setup.py) egg_info for package pymongo

Installing collected packages: pymongo
Running setup.py install for pymongo
building 'bson._cbson' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ibson -I/usr/include/python2.7 -c bson/_cbsonmodule.c -o build/temp.linux-x86_64-2.7/bson/_cbsonmodule.o
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ibson -I/usr/include/python2.7 -c bson/time64.c -o build/temp.linux-x86_64-2.7/bson/time64.o
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ibson -I/usr/include/python2.7 -c bson/buffer.c -o build/temp.linux-x86_64-2.7/bson/buffer.o
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ibson -I/usr/include/python2.7 -c bson/encoding_helpers.c -o build/temp.linux-x86_64-2.7/bson/encoding_helpers.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/bson/_cbsonmodule.o build/temp.linux-x86_64-2.7/bson/time64.o build/temp.linux-x86_64-2.7/bson/buffer.o build/temp.linux-x86_64-2.7/bson/encoding_helpers.o -o build/lib.linux-x86_64-2.7/bson/_cbson.so
building 'pymongo._cmessage' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ibson -I/usr/include/python2.7 -c pymongo/_cmessagemodule.c -o build/temp.linux-x86_64-2.7/pymongo/_cmessagemodule.o
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Ibson -I/usr/include/python2.7 -c bson/buffer.c -o build/temp.linux-x86_64-2.7/bson/buffer.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/pymongo/_cmessagemodule.o build/temp.linux-x86_64-2.7/bson/buffer.o -o build/lib.linux-x86_64-2.7/pymongo/_cmessage.so

Successfully installed pymongo
Cleaning up...
因此,您认为pymongo已经安装,但Python无法识别它:

$ python -c "import pymongo"

Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named pymongo 

请尝试从以下来源安装:

$ git clone git://github.com/mongodb/mongo-python-driver.git pymongo
$ cd pymongo/
$ python setup.py install
不要忘记它的依赖关系:

sudo apt-get install build-essential python-dev

你有两个版本的Python安装在同一台机器上吗?是的,我有,2.7和3.4我在我的机器上有类似的东西,我想你安装了pymongo版本3.4。通过遵循Dex说明(
python setup.py install
),您明确地调用了2.7版的
setup.py
脚本。非常感谢!这很有魅力,知道pip安装失败的原因吗?(仅供个人学习)安装问题不属于源代码的主题。依赖项在特定软件包的
setup.py
中使用“install_requires”配置正确定义,因此这可能就是原因。看起来您最初安装的pymongo版本是3.4。按照@Dex的说明,您现在也为Python 2.7安装了它。但是macOS没有apt get,我想知道自制的“build essential”对应的包名是什么?
$ git clone git://github.com/mongodb/mongo-python-driver.git pymongo
$ cd pymongo/
$ python setup.py install
sudo apt-get install build-essential python-dev