Skip to content
This repository has been archived by the owner. It is now read-only.

pip does not working with virtualenv #5458

Closed
m-messiah opened this Issue Nov 2, 2016 · 20 comments

Comments

Projects
None yet
10 participants
@m-messiah
Copy link

m-messiah commented Nov 2, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

pip

ANSIBLE VERSION
2.2.0.0
CONFIGURATION

None

OS / ENVIRONMENT

Debian Jessie

SUMMARY

PIP does not work with pyvenv-3.5 after update to ansible 2.2

STEPS TO REPRODUCE

Task

- name: Update setuptools and pip
  become: true
  become_user: "www-data"
  pip: name={{ item }} state=latest virtualenv=/www/env/site virtualenv_command=pyvenv-3.5
  with_items:
    - pip
    - setuptools
    - wheel
EXPECTED RESULTS

Successful update of pip and others in /www/env/site virtualenv

ACTUAL RESULTS

Fails on update system pip2

failed: [test] (item=setuptools) => {"cmd": "/usr/local/bin/pip2 install -U setuptools", "failed": true, "item": "setuptools", "msg": "stdout: Collecting setuptools\n  Using cached setuptools-28.7.1-py2.py3-none-any.whl\nInstalling collec
ted packages: setuptools\n  Found existing installation: setuptools 25.1.6\n    Uninstalling setuptools-25.1.6:\n\n:stderr: Exception:\nTraceback (most recent call last):\n  File \"/usr/local/lib/python2.7/dist-packages/pip-8.1.2-py2.7.eg
g/pip/basecommand.py\", line 215, in main\n    status = self.run(options, args)\n  File \"/usr/local/lib/python2.7/dist-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py\", line 317, in run\n    prefix=options.prefix_path,\n  File \"/u
sr/local/lib/python2.7/dist-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py\", line 736, in install\n    requirement.uninstall(auto_confirm=True)\n  File \"/usr/local/lib/python2.7/dist-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py\
", line 742, in uninstall\n    paths_to_remove.remove(auto_confirm)\n  File \"/usr/local/lib/python2.7/dist-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py\", line 115, in remove\n    renames(path, new_path)\n  File \"/usr/local/lib
/python2.7/dist-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py\", line 267, in renames\n    shutil.move(old, new)\n  File \"/usr/lib/python2.7/shutil.py\", line 303, in move\n    os.unlink(src)\nOSError: [Errno 13] Permission denied:
'/usr/local/bin/easy_install'\n"}
@danilodemorais

This comment has been minimized.

Copy link

danilodemorais commented Nov 2, 2016

I had the same issue yesterday, it seems that the task is ignoring the virtualenv parameter. To work around it, I removed virtualenv_command and passed the pip executable directly executable={{ app_root_directory }}/env/bin/pip

@m-messiah

This comment has been minimized.

Copy link
Author

m-messiah commented Nov 2, 2016

@daniloriecken nice workaraund, but it would not work with creation of virtualenv.
So, my workaround is downgrade ansible =(

@ansibot

This comment has been minimized.

Copy link

ansibot commented Nov 2, 2016

@mattupstate, ping. This issue is waiting on your response.
click here for bot help

@adamchainz

This comment has been minimized.

Copy link
Contributor

adamchainz commented Nov 2, 2016

For me on an existing install I found it fails at upgrading pip, not setuptools or wheel, because it seems to be trying to upgrade the system-wide pip.

@m-messiah you can work around creating a virtualenv with something like:

- name: virtualenv exists
  become_user: www-data
  command: virtualenv --python=/path/to/python3 /path/to/venv
  args:
    creates: /path/to/venv/bin/python
@d3prof3t

This comment has been minimized.

Copy link
Contributor

d3prof3t commented Nov 5, 2016

I have also encountered the same issue of pip module not working with python3.5
My OS is Fedora 24.

Playbook Snippet

- name: Install dependecies in the new VirtualEnv
  pip:    requirements={{ app_dir }}/requirements.txt
          virtualenv={{ venv_dir }}
          virtualenv_python=python3.5

In my case the virtualenv_python argument does not seem to work. Instead all my dependencies of requirements.txt get installed in global site packages of python2.7

@abadger

This comment has been minimized.

Copy link
Member

abadger commented Nov 5, 2016

This should be fixed in d2106f1 for devel and 8f0ab37 for stable-2.2. Will be in the 2.2.1 release.

Using the playbook task from the original comment:

$ ansible-playbook 5458.yml                                     (11:18:05)
 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] ****************************************************************************************************

TASK [setup] ********************************************************************************************************
ok: [localhost]

TASK [Update setuptools and pip] ************************************************************************************
changed: [localhost] => (item=pip)
changed: [localhost] => (item=setuptools)
changed: [localhost] => (item=wheel)

PLAY RECAP **********************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0   

[pts/13@roan /srv/ansible/troubleshooting]$ ansible-playbook 5458.yml                                     (11:18:37)
 [WARNING]: provided hosts list is empty, only localhost is available


PLAY [localhost] ****************************************************************************************************

TASK [setup] ********************************************************************************************************
ok: [localhost]

TASK [Update setuptools and pip] ************************************************************************************
ok: [localhost] => (item=pip)
ok: [localhost] => (item=setuptools)
ok: [localhost] => (item=wheel)

PLAY RECAP **********************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0 
$ ansible-playbook --version                                    (11:18:45)
ansible-playbook 2.3.0 (devel 2131eaba0c) last updated 2016/11/04 07:32:46 (GMT -700)
  lib/ansible/modules/core: (devel 76fd19c3ca) last updated 2016/11/02 12:54:17 (GMT -700)
  lib/ansible/modules/extras: (devel cee034dd89) last updated 2016/11/02 17:39:48 (GMT -700)
  config file = /srv/ansible/troubleshooting/ansible.cfg
  configured module search path = Default w/o overrides

If you wish to get the fix immediately, it's possible to download the version of pip.py from the github repository and install it into your ANSIBLE_LIBRARY path (or overwrite your system copy): https://raw.githubusercontent.com/ansible/ansible-modules-core/devel/packaging/language/pip.py

If you find that using the latest version of the pip.py module does not fix the issue, please open a new issue with your playbook task so we can figure out what's different in your case versus this case. Thanks!

@abadger abadger closed this Nov 5, 2016

@d3prof3t

This comment has been minimized.

Copy link
Contributor

d3prof3t commented Nov 6, 2016

Thanks a lot @abadger

@cultavix

This comment has been minimized.

Copy link

cultavix commented Nov 14, 2016

Same exact issue. Virtualenv is created, but the packages from requirements.txt are being installed globally. What is the verdict on the best work-around ?

 - name: virtualenv - Install requirements
      become: no
      when: service in virtualenv_services
      pip:
        requirements: "{{ service_location }}/requirements.txt"
        virtualenv: "{{ service_location }}/virtualenv"
        virtualenv_python: "{{ virtualenv_python_version | default('python2.7') }}"
@adamchainz

This comment has been minimized.

Copy link
Contributor

adamchainz commented Nov 14, 2016

Use the latest pip.py as toshi wrote above

On Mon, 14 Nov 2016 at 11:49, James Gonzalez notifications@github.com
wrote:

Same exact issue. Virtualenv is created, but the packages from
requirements.txt are being installed globally. What is the verdict on the
best work-around ?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#5458 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA0WCWpQ-qh2zQ30IJJ3tzcoDya26panks5q-Eq_gaJpZM4KnFrY
.

@d3prof3t

This comment has been minimized.

Copy link
Contributor

d3prof3t commented Nov 14, 2016

@cultavix Hey! As @abadger suggested to download and use the latest version of pip file from https://raw.githubusercontent.com/ansible/ansible-modules-core/devel/packaging/language/pip.py or wait till the stable 2.2.1 is out.

For me, I just rolled back my installation to 2.1.3, all the issues atleast pertaining to pip as you mentioned above are fixed now!

@cultavix

This comment has been minimized.

Copy link

cultavix commented Nov 14, 2016

Thanks, so I've actually gone with the solution proposed by @daniloriecken where I just pass in the pip command manually, within the virtualenv and that has solved the problem.

@m-messiah

This comment has been minimized.

Copy link
Author

m-messiah commented Nov 28, 2016

Hey, what about 2.2.1 or 2.2.0.1? A month went out, but there are no changes in PyPI or other.

@cultavix

This comment has been minimized.

Copy link

cultavix commented Dec 14, 2016

I'm trying it out now. Will come back with an update. Thanks

Update: Ansible 2.2.1+ is not available on PyPI. (pip)

@Kyslik

This comment has been minimized.

Copy link

Kyslik commented Feb 23, 2017

@d3prof3t where is the pip.py located (so I can replace it)?

I am on OS X Yosemite and using homebrew to install Ansible.

@d3prof3t

This comment has been minimized.

Copy link
Contributor

d3prof3t commented Feb 23, 2017

@Kyslik what is your ansible version?

@Kyslik

This comment has been minimized.

Copy link

Kyslik commented Feb 23, 2017

@d3prof3t

This comment has been minimized.

Copy link
Contributor

d3prof3t commented Feb 26, 2017

@Kyslik I don't use OSX, so can't be sure about it particularly.

@bearrito

This comment has been minimized.

Copy link

bearrito commented Jun 19, 2017

I can replicate this on Ubuntu 16.04 with Ansible 2.3

@abadger

This comment has been minimized.

Copy link
Member

abadger commented Jun 19, 2017

If you're having this issue, please file a new bug on https://github.com/ansible/ansible with complete information for us to reproduce. This was fixed via the mentioned commits. However, there has been recent work done to try to fix an issue where the fix for Ubuntu's version of virtualenv breaks /usr/bin/pyvenv so if this has regressed in devel we need to know.

New comments to closed bugs are often not seen by anyone with commit rights as the closed tickets are not part of our workflow. It's just by chance that I happened to see the new comment to this bug so please file a new bug so we can check out what might be going wrong.

@btoueg

This comment has been minimized.

Copy link

btoueg commented Jul 4, 2017

I have the exact same problem as @cultavix, with ansible 2.3.1.0 installed with brew on macOS Sierra 10.12.5

Same exact issue. Virtualenv is created, but the packages from requirements.txt are being installed globally. What is the verdict on the best work-around ?

  • name: virtualenv - Install requirements
    become: no
    when: service in virtualenv_services
    pip:
    requirements: "{{ service_location }}/requirements.txt"
    virtualenv: "{{ service_location }}/virtualenv"
    virtualenv_python: "{{ virtualenv_python_version | default('python2.7') }}"
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.