Pip states report "AttributeError: 'Requirement' object has no attribute 'project_name'" since python-pip (8.1.1-2ubuntu0.1)

Bug #1586381 reported by Graham Clinch
78
This bug affects 16 people
Affects Status Importance Assigned to Milestone
One Hundred Papercuts
Fix Released
Medium
Unassigned
salt (Ubuntu)
Fix Released
Medium
Unassigned
Xenial
Invalid
Undecided
Unassigned

Bug Description

Pip changed an internal API, which was then cherry-picked into python-pip (8.1.1-2ubuntu0.1). Salt relies on this API for the 'pip' states, which now report:

[ERROR ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1626, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1492, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 592, in installed
    out = _check_pkg_version_format(pkg)
  File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 176, in _check_pkg_version_format
    ret['prefix'] = install_req.req.project_name
AttributeError: 'Requirement' object has no attribute 'project_name'

This has been reported (and patched) upstream: https://github.com/saltstack/salt/pull/33180

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: salt-minion 2015.8.8+ds-1
ProcVersionSignature: Ubuntu 4.4.0-22.40-generic 4.4.8
Uname: Linux 4.4.0-22-generic x86_64
ApportVersion: 2.20.1-0ubuntu2
Architecture: amd64
Date: Fri May 27 13:46:42 2016
JournalErrors:
 Hint: You are currently not seeing messages from other users and the system.
       Users in groups 'adm', 'systemd-journal' can see all messages.
       Pass -q to turn off this notice.
 -- No entries --
PackageArchitecture: all
SourcePackage: salt
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Graham Clinch (g-clinch) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in salt (Ubuntu):
status: New → Confirmed
Changed in salt (Ubuntu):
importance: Undecided → Medium
Changed in hundredpapercuts:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Graham Clinch (g-clinch) wrote :

Attached is a debian/patches version of salt pull #33180 (https://github.com/saltstack/salt/pull/33180/files) which corrects this issue

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "salt-33180.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Revision history for this message
Daniel Waites (bigdwaites) wrote :

Would like to point out this same bug prevents current Amazon Web Services command line tools from being installed via pip, and the packaged version (via apt) is fairly old. I was able to force downgrade pip to the older version from the xenial release and get the AWS CLI working again.

Revision history for this message
Florin Andrei (florin-andrei) wrote :

It also breaks TensorFlow and a lot of other things.

The workaround is to do "pip install --upgrade pip" to apply the fix from upstream, but the Ubuntu package is still broken.

Please fix, this is a pretty serious issue for anyone using Python on Ubuntu.

Revision history for this message
Andrew Meyer (andrewm-bpi) wrote :

This bug also seems to makes it impossible to update pip to a specific version using `pip install --upgrade pip==<version>` or `pip install <pip-package-url>` or `pip install <pip-package-file>`.

E.g:

```
# pip install pip-8.1.2-py2.py3-none-any.whl
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))

  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 448, in _prepare_file
    req_to_install, finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 387, in _check_skip_installed
    req_to_install.check_if_exists()
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 1011, in check_if_exists
    self.req.project_name
AttributeError: 'Requirement' object has no attribute 'project_name'
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
```

Only `pip install --upgrade pip` (with no version constraint) works as expected.

For deploys on machines which don't have internet access (and thus can't access PyPI directly) this problem is very inconvenient.

Revision history for this message
Andrew Meyer (andrewm-bpi) wrote :

Steps to reproduce:

On a fresh install of Ubuntu 16.01 LTS, run:

    sudo apt-get install pip
    sudo -H pip install pip==6.1.1

Receive the following error message:

```
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)

  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 448, in _prepare_file
    req_to_install, finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 387, in _check_skip_installed
    req_to_install.check_if_exists()
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 1011, in check_if_exists
    self.req.project_name
AttributeError: 'Requirement' object has no attribute 'project_name'
```

Revision history for this message
Andrew Meyer (andrewm-bpi) wrote :

Make that:

    sudo apt-get -y install python-pip
    sudo -H pip install pip==9.0.1

For whatever reason it seems I can't edit my past comments. Also, the above comment was meant to be in reference to me adding `python-pip` to the list of packages affected by this bug.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python-pip (Ubuntu):
status: New → Confirmed
Changed in python-pip (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Colin Watson (cjwatson) wrote :

This may have been fixed by the fix for bug 1626258. Could you check? If so, I think this bug can be marked as a duplicate.

Revision history for this message
Andrew Meyer (andrewm-bpi) wrote :

I can confirm that I recently stopped experiencing this issue. No idea whether that's because of the changes made to fix bug #1626258 or not though.

Revision history for this message
Colin Watson (cjwatson) wrote :

I think it probably is, so let's dup this at least for now. Somebody can always undo that later if there turns out to be more to it than that.

Revision history for this message
Graham Clinch (g-clinch) wrote :

I do not believe this is a duplicate of bug #1626258 as I continue to experience the reported issue with salt:

```
python-pip:
  Installed: 8.1.1-2ubuntu0.4
salt-minion:
  Installed: 2015.8.8+ds-1

$ salt-call state.highstate
[...]
    Function: pip.installed
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1626, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1492, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 592, in installed
                  out = _check_pkg_version_format(pkg)
                File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 176, in _check_pkg_version_format
                  ret['prefix'] = install_req.req.project_name
              AttributeError: 'Requirement' object has no attribute 'project_name'
```

The patch for bug #1626258 does not return pip to supplying 'project_name', rather it fixes up other parts of pip which expect (as salt does) 'project_name', and it does so by referencing 'name'.

Revision history for this message
Colin Watson (cjwatson) wrote :

Fair enough; unduplicating, then.

Revision history for this message
Benjamin Drung (bdrung) wrote :

The fix is part of upstream release 2015.8.9 and 2016.11. Therefore it is fixed in Ubuntu 17.10 (artful) and later.

Changed in salt (Ubuntu Xenial):
status: New → Confirmed
Changed in salt (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python-pip (Ubuntu Xenial):
status: New → Confirmed
no longer affects: python-pip (Ubuntu)
no longer affects: python-pip (Ubuntu Xenial)
Revision history for this message
Paul White (paulw2u) wrote :

Ubuntu 16.04 (xenial) reached end-of-life on April 29, 2021.

Further to comment #16 this issue was fixed but probably not in all releases. Closing.

Changed in salt (Ubuntu Xenial):
status: Confirmed → Invalid
Changed in hundredpapercuts:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.