Frage

I have been using this command for quite some time, and until recently it worked very well.

alias pipup='sudo pip install --upgrade $(yolk -U | awk "{print $1} ")'

However, it has recently started failing with the following output any time a package has an available update:

Exception:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/install.py", line 257, in run
    InstallRequirement.from_line(name, None))
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req.py", line 172, in from_line
    return cls(req, comes_from, url=url, prereleases=prereleases)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req.py", line 70, in __init__
    req = pkg_resources.Requirement.parse(req)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/pkg_resources.py", line 2606, in parse
    reqs = list(parse_requirements(s))
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/pkg_resources.py", line 2532, in parse_requirements
    raise ValueError("Missing distribution spec", line)
ValueError: ('Missing distribution spec', '(1.5.4)')

Storing debug log for failure in /Users/Bryson/.pip/pip.log

The output of the yolk -U command executed by this alias in this instance was:

[14:05] Bryson@Zeus ~ :$ yolk -U
 pep8 1.5.3 (1.5.4)
 setuptools 3.4.1 (3.4.3)
[14:06] Bryson@Zeus ~ :$ 

When there are no package names/versions returned by yolk, the command instead outputs the following properly and the alias command does not fail. Instead the following is correctly printed to the terminal:

No newer packages found at The Cheese Shop
You must give at least one requirement to install (see "pip help install")
War es hilfreich?

Lösung

Your problem is that the $1 in awk "{print $1} " is being interpolated as a variable, resulting in the command awk "{print }" being executed. This latter command prints the entire line (not just the first field), and so causes (1.5.4) to appear on pip's commandline.

It probably worked for a while because yolk -U wasn't outputting anything.

To fix, you can escape the $:

alias pipup='sudo pip install --upgrade $(yolk -U | awk "{print \$1}")'

or just use cut:

alias pipup='sudo pip install --upgrade $(yolk -U | cut -d" " -f 2)'
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top