2016-09-16 71 views
0

我試圖安裝PyMongo Python包與pip。它需要Ansible mongodb_user moduleImportError:沒有名爲pymongo的模塊

我安裝點子並與以下Ansible腳本pymongo:

- hosts: tag_Name_Development 
    become: true 
    remote_user: user 
    tasks: 
    - name: install python tools 
     yum: name={{ item }} state=latest 
     with_items: 
     - gcc 
     - python-devel 
     - python-setuptools 
     - python-pip 

    - name: install pymongo 
     pip: name=pymongo state=latest 

    - name: add admin user to mongo 
     mongodb_user: 
     login_port: 27017 
     database: admin 
     name: admin 
     password: "{{ mongodb.admin_pass }}" 
     roles: userAdminAnyDatabase 
     state: present 

成功安裝的我獲得以下Ansible錯誤的工具後。在安裝pymongo

FAILED! => {"changed": false, "failed": true, "msg": "the python pymongo module is required"}

在服務器上,我得到

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

其他相關信息pip freezepip list

$ python-pip freeze 
backports.ssl-match-hostname==3.4.0.2 
ordereddict==1.2 
pymongo==3.3.0 

$ python-pip list 
backports.ssl-match-hostname (3.4.0.2) 
ordereddict (1.2) 
pip (6.1.1) 
pymongo (3.3.0) 
setuptools (12.2) 

,並加載路徑

$ python 
Python 2.7.10 (default, Jul 20 2016, 20:53:27) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import sys 
>>> sys.path 
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/local/lib64/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages', '/usr/lib64/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages'] 

還有很多其他問題與這個問題有關,但沒有一個幫助。我沒有安裝bson,我沒有使用任何虛擬環境。

回答

0

原來,我有兩個版本的python安裝(2.6和2.7)。雖然默認是2.7,我Ansible腳本2.6文件夾/usr/local/lib64/python2.6/site-packages

下安裝pymongo我發現了運行$ python-pip show pymongo$ python2.6 -c "import pymongo"按預期工作。

我改變了我的Ansible腳本安裝python27-pip而不是python-pip,它開始很好地工作。

相關問題