2015-11-03 77 views
3

我试图让pymongo在我们的linux服务器上运行,但是某些操作失败了,但我不知道是什么。虽然安装了pymongo ImportError

我有我的本地机器上运行(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 

而且在Python本身:

$ python 
Python 2.7.9 (default, Nov 3 2015, 14:21:40) 
[GCC 4.9.1] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import pymongo 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
ImportError: No module named pymongo 
>>> exit() 

没有人有任何线索?我没有在我的Mac这个问题

$ python -V 
Python 2.7.9 
+0

你有两个版本的Python安装在同一台机器上? – Jaco

+0

是我做的,2.7和3.4 –

+0

我有我的机器上类似的东西,我觉得你安装了3.4版本pymongo。按照Dex指令('python setup.py install'),你明确地称为2.7的'setup.py'脚本。 – Jaco

回答

1

尝试从源安装:

$ 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 
+1

非常感谢!这就像一个魅力,任何想法为什么点安装失败? (仅供个人学习) –

+0

安装问题不是源代码的主题。依赖关系在使用'install_requires'配置的特定软件包的'setup.py'内部正确定义,所以也许这就是原因。 – 2015-11-03 14:05:16

+0

看来你最初为3.4版安装了pymongo。通过遵循@Dex指令,您现在也为Python 2.7安装了它。 – Jaco

相关问题