Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install pip3 package using ansible instead of pip2

I am trying to setup a Django project in vagrant using ansible. I have used the following code for installing the pip packages:

- name: Setup Virtualenv
  pip: virtualenv={{ virtualenv_path }} virtualenv_python=python3 requirements={{ virtualenv_path }}/requirements.txt

I need to use python3 for the django project and even though I have explicitly mentioned to use python3, it is installing the pip packages via pip2. I have ensured that python3 is installed on the virtual machine.

Please, help me install the packages via pip3.

like image 611
kamayani Avatar asked Jun 09 '17 10:06

kamayani


People also ask

What is pip pip2 pip3?

pip and pip2, pip3pip2 is the command used to manage packages used by Python2, and pip3 is the command used to manage packages used by Python3. pip is assigned to either Python2 or Python3. For example, note that if pip is for Python2, packages installed with pip will not work with Python3.

Can I install pip without Sudo?

We'll be installing pip for Python 2 using the get-pip.py script. Pip will be installed globally. If you want to install it only for your user, run the command without sudo . The script will also install setuptools and wheel , which allow you to install source distributions.

What version of Pip do I use in Ansible?

Although it executes using the Ansible Python interpreter, the pip module shells out to run the actual pip command, so it can use any pip version you specify with executable. By default, it uses the pip version for the Ansible Python interpreter. For example, pip3 on python 3, and pip2 or pip on python 2.

How to install ansible in Python?

You can install Ansible on many systems with pip. Pip is the main Python package manager. If pip is not already have been installed on your system, then you must execute upcoming commands to install all package into your system. After passing the installation of pip software , you can install Ansible.

What is the use of Pip in Debian?

Pip is a package management system used to install and manage software packages written in Python. Pip is mostly used to install packages available in Python Package Index (PyPI). Developers can also use Pip to install modules and packages developed locally. The default installation of Debian 10 doesn’t come with Pip.

What is ‘forcereinstall’ in Ansible?

The ‘forcereinstall’ option is only available in Ansible 2.1 and above. The system umask to apply before installing the pip package. This is useful, for example, when installing on systems that have a very restrictive umask by default (e.g., “0077”) and you want to pip install packages which are to be used by all users.


2 Answers

Try to use executable option. Excerpt from pip module doc:

executable (added in 1.3)

The explicit executable or a pathname to the executable to be used to run pip for a specific version of Python installed in the system. For example pip-3.3, if there are both Python 2.7 and 3.3 installations in the system and you want to run pip for the Python 3.3 installation. It cannot be specified together with the 'virtualenv' parameter (added in 2.1). By default, it will take the appropriate version for the python interpreter use by ansible, e.g. pip3 on python 3, and pip2 or pip on python 2.

Update:

To combine virtualenv path and alternative executable, use virtualenv_command like this:

- pip:
    virtualenv: /tmp/py3
    virtualenv_command: /usr/bin/python3 -m venv
    name: boto

Absolute path is required for virtualenv_command.

like image 145
Konstantin Suvorov Avatar answered Sep 20 '22 21:09

Konstantin Suvorov


Had the same issue. There is workaround with usage executable:

- name: Install and upgrade pip
  pip:
    name: pip
    extra_args: --upgrade
    executable: pip3
like image 30
Nikita Shesterikov Avatar answered Sep 17 '22 21:09

Nikita Shesterikov