How to install Ansible to run under Python3 on Amazon Linux?
Solution 1
This worked:
sudo yum -y install python3 python3-pip
sudo pip3 install ansible
the key was to install python3 this way instead of the way I did originally, after that ansible will install correctly
Solution 2
I think it's possible that you have a previous Ansible
installation with Python2
. Try this:
~$ pip uninstall ansible
Then try running the following command again.
~$ ansible --version | egrep 'python version'
Related videos on Youtube
kavise
Updated on June 04, 2022Comments
-
kavise almost 2 years
There are directions here: https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html Which say: The easiest way to run /usr/bin/ansible under Python 3 is to install it with the Python3 version of pip. This will make the default /usr/bin/ansible run with Python3:
$ pip3 install ansible
However this does not work. It will install ansible, but ansible still uses Python2:
$ ansible --version | grep "python version" python version = 2.7.14 (default, Jul 26 2018, 19:59:38) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
I installed Python3 first, then pip, then Ansible (not sure if the order matters)
The Ansible version is 2.7.8. The ami is ami-095cd038eef3e5074 (latest amazoninux base).
Does anyone know of a way to get this working? Thanks much for any help
-
jensmtg about 5 yearsYou could try something like
apt-get install python-minimal python3-setuptools aptitude -y && easy_install3 pip
. (You may need toapt-get update
first.) Then you should be able to run pip3 aspip
.
-
-
kavise about 5 yearsansible is not installed but Python2 is pre-installed. The exact commands I’m running are: sudo yum install python3 sudo easy_install pip sudo pip3 install ansible I tried changing the order to install pip3 before python3, and using pip3 to install Python3 instead of yum, this was the result: Collecting python3 Could not find a version that satisfies the requirement python3 (from versions: ) No matching distribution found for python3
-
kavise about 5 yearsthe first command result is: no package available. The second command result is: command not found... when I do a "pip --version" I get this: pip 19.0.3 from /usr/lib/python2.7/site-packages/pip-19.0.3-py2.7.egg/pip (python 2.7) "pip3 --version" gives the same result
-
error404 about 5 yearsEdited the answer try the above
-
insideClaw over 3 yearsExcellent and to the point, just two additions: 1. Never run pip as root, it can create dependency hells with other package managers and is not needed. 2. You may want to ensure your existing Ansible with Python2 is removed first, be it via pip or apt.