Salt: The `pip.installed` state is unable to use `pip3` when no `pip` for python2 installed

Created on 15 Mar 2017  Â·  7Comments  Â·  Source: saltstack/salt

Description of Issue/Question

I'm trying to install aiohttp module for Python 3.5 with pip3 using Salt. I don't have pip version for Python 2 installed at all.

Setup

# python3/aiohttp.sls

Install Python 3.5 and pip:
  pkg.installed:
    - pkgs:
      - python3
      - python3-pip
    - reload_modules: true

Install aiohttp:
  pip.installed:
    - name: aiohttp
    - require:
      - pkg: Install Python 3.5 and pip

Steps to Reproduce Issue

What I've got is this:

# salt-call state.apply python3.aiohttp
local:
----------
          ID: Install Python 3.5 and pip
    Function: pkg.installed
      Result: True
     Comment: All specified packages are already installed
     Started: 14:53:38.014280
    Duration: 30.274 ms
     Changes:   
----------
          ID: Install aiohttp
    Function: pip.installed
        Name: aiohttp
      Result: False
     Comment: An importable pip module is required but could not be found on your system. This usually means that the system's pip package is not installed properly.
     Started: 14:53:38.408579
    Duration: 0.582 ms
     Changes:   

It seems that the pip state module is depending on pip for Python 2 module availability, because Salt Minion is running againts Python 2.

The workaround for this which I came with so far:

Install Python 3.5 and pip:
  pkg.installed:
    - pkgs:
      # Python 2 ``pip`` is required for ``pip.installed`` state to work
      - python-pip
      - python3
      - python3-pip
    - reload_modules: true

Install aiohttp:
  pip.installed:
    - name: aiohttp
    - bin_env: /usr/bin/pip3
    - require:
      - pkg: Install Python 3.5 and pip

Versions Report

Salt Version:
           Salt: 2016.11.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
        machine: x86_64
expected-behavior

Most helpful comment

@gtmanfred I agree with @vutny that this is at best confusing behavior, and should be documented if it can't be changed. If I am using python3, and thus pip3, I don't really want to have pip2 be a dependancy. Currently this doesn't work:

python34_pip_package:
  pkg:
    - installed
    - name: python34-pip

boto3_package:
  pip.installed:
    - require:
      - pkg: python34_pip_package
    - bin_env: '/bin/pip3'
    - name: boto3 == 1.4.4

while this does:

python2_pip_package:
  pkg:
    - installed
    - name: python2-pip

python34_pip_package:
  pkg:
    - installed
    - name: python34-pip

boto3_package:
  pip.installed:
    - require:
      - pkg: python34_pip_package
    - bin_env: '/bin/pip3'
    - name: boto3 == 1.4.4

It is not the need for the bin_env line that is the problem; it is the requirement for pip2 to be installed when it is explicitly not what I want to use.

All 7 comments

I consider this the expected behavior.

The module defaults to using pip, if it is not available, the correct pip to be used will need to be specified.

Thanks,
Daniel

@gtmanfred Sorry, I think I missed the important point: if I do not have pip installed and trying to use available pip3 binary explicitly:

Install aiohttp:
  pip.installed:
    - name: aiohttp
    - bin_env: /usr/bin/pip3

It gives me the same error:

An importable pip module is required but could not be found on your system. This usually means that the system's pip package is not installed properly.

It starts working only then the pip got installed.
Does that still looks like the expected behavior?

@gtmanfred I agree with @vutny that this is at best confusing behavior, and should be documented if it can't be changed. If I am using python3, and thus pip3, I don't really want to have pip2 be a dependancy. Currently this doesn't work:

python34_pip_package:
  pkg:
    - installed
    - name: python34-pip

boto3_package:
  pip.installed:
    - require:
      - pkg: python34_pip_package
    - bin_env: '/bin/pip3'
    - name: boto3 == 1.4.4

while this does:

python2_pip_package:
  pkg:
    - installed
    - name: python2-pip

python34_pip_package:
  pkg:
    - installed
    - name: python34-pip

boto3_package:
  pip.installed:
    - require:
      - pkg: python34_pip_package
    - bin_env: '/bin/pip3'
    - name: boto3 == 1.4.4

It is not the need for the bin_env line that is the problem; it is the requirement for pip2 to be installed when it is explicitly not what I want to use.

Thanks for bumping this up @nbirnel

The pip module does not require that pip2 be installed to load it.

We import it for doing version comparisons it looks like.

https://github.com/saltstack/salt/blob/develop/salt/states/pip_state.py#L111

This should work fine in 2017.7.0 if you run salt under python3

But this does not only use the pip binary when you specify bin_env.

@gtmanfred Thanks for clarifying. I'm running 2016.11.5, but it is nice to know this will be cleaned up soon.

Would a PR for documentation be welcome on this? eg describe the workaround, and point to the later change?

Yup, that would be awesome!
On Thu, Jul 13, 2017 at 5:36 PM Noah Birnel notifications@github.com
wrote:

@gtmanfred https://github.com/gtmanfred Thanks for clarifying. I'm
running 2016.11.5, but it is nice to know this will be cleaned up soon.

Would a PR for documentation be welcome on this? eg describe the
workaround, and point to the later change?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/saltstack/salt/issues/40048#issuecomment-315230140,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAssoc7zpy6s0bsVICobGrlcSdo8egkJks5sNqoZgaJpZM4MeGqn
.

Was this page helpful?
0 / 5 - 0 ratings