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 on 2016-05-27
78
This bug affects 16 people
Affects Status Importance Assigned to Milestone
One Hundred Papercuts
Medium
Unassigned
python-pip (Ubuntu)
Medium
Unassigned
Xenial
Undecided
Unassigned
salt (Ubuntu)
Medium
Unassigned
Xenial
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)

Graham Clinch (g-clinch) wrote :
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
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

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
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.

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.

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.

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'
```

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.

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
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.

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.

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.

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'.

Colin Watson (cjwatson) wrote :

Fair enough; unduplicating, then.

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
Launchpad Janitor (janitor) wrote :

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

Changed in python-pip (Ubuntu Xenial):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers