我试图用pip安装PyMongo Python包。 Ansible mongodb_user module需要它。
我正在使用以下Ansible脚本安装pip和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错误。
FAILED! => {"changed": false, "failed": true, "msg": "the python pymongo module is required"}
在安装了pymongo
的服务器上,我得到了
$ python -c "import pymongo"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named pymongo
其他相关信息pip freeze
和pip 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 :(得分:0)
原来我安装了两个版本的python(2.6和2.7)。即使默认值为2.7,我的Ansible脚本也会在2.6文件夹pymongo
/usr/local/lib64/python2.6/site-packages
我发现通过运行$ python-pip show pymongo
和$ python2.6 -c "import pymongo"
可以正常工作。
我更改了我的Ansible脚本以安装python27-pip
而不是python-pip
,并且它开始运行良好。
答案 1 :(得分:0)
我有类似的问题。我通过将PIP安装目录附加到PYTHON_PATH并更改PIP安装目录的权限来解决它。