pymongo installed but import fails

此生再无相见时 提交于 2019-12-11 08:25:38

问题


CentOS 5.8 ships with Python 2.4.3. I installed pymongo using command: sudo pip install pymongo (after installing pip with easy_install after installing python-pip...typical CentOS, nothing works out of the box).

The install appears to work, I get the messages:

    Successfully installed pymongo
    Cleaning up...

Then, when I run import pymongo, I get this:

ImportError: No module named pymongo

I followed the standard pymongo install procedure so pymongo definitely doesn't work on CentOS. Anybody know of a workaround to get this working? It seems yet again, a hack is required to make CentOS support basic functionality every other Linux distro supports out of the box....


回答1:


Since you didn't specify you need to use the default CentOS Python install, I would highly recommend using virtualenv to get the support you want. CentOS requires that old version of Python, and we have to work around it at my business as well.

Grab the latest Python, and build from source. Make sure any SSL devel libraries are installed through Yum.

./configure --prefix=/home/user/custompython
make && make install

Grab virtualenv.py from https://raw.github.com/pypa/virtualenv/master/virtualenv.py and run that script from your custom python install

/home/user/custompython/bin/python virtualenv.py -P /home/user/custompython/bin/python /home/user/pythonENV
export PYTHON_HOME=/home/user/pythonENV/
export PATH=/home/user/pythonENV/bin/:$PATH
pip install pymongo

Of course, adding the path modifications to .bashrc is helpful. Now you can install anything you want without worrying about the very old 2.4.3 that CentOS ships with. This is the exact setup I have with our CentOS 5.8 system, and it is very helpful.



来源:https://stackoverflow.com/questions/10743630/pymongo-installed-but-import-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!