python 3.7 - How to fix error “Expected version spec in …” using pip install on Windows?




download 3.4 (4)

On a Windows 7 machine I am using the following command to install a package from a local directory:

pip install addons/pnc_tests --upgrade --extra-index-url=http://some_server/simple

which results in the following error:

C:\Users\alex\PNC\tas\ENV\Scripts\pip-script.py run on 07/16/14 07:50:47

Exception:
Traceback (most recent call last):
  File "C:\Users\alex\PNC\tas\ENV\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Users\alex\PNC\tas\ENV\lib\site-packages\pip\commands\install.py", line 258, in run
    InstallRequirement.from_line(name, None))
  File "C:\Users\alex\PNC\tas\ENV\lib\site-packages\pip\req.py", line 173, in from_line
    return cls(req, comes_from, url=url, prereleases=prereleases)
  File "C:\Users\alex\PNC\tas\ENV\lib\site-packages\pip\req.py", line 71, in __init__
    req = pkg_resources.Requirement.parse(req)
  File "C:\Users\alex\PNC\tas\ENV\lib\site-packages\pip\_vendor\pkg_resources.py", line 2667, in parse
    reqs = list(parse_requirements(s))
  File "C:\Users\alex\PNC\tas\ENV\lib\site-packages\pip\_vendor\pkg_resources.py", line 2605, in parse_requirements
    line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec")
  File "C:\Users\alex\PNC\tas\ENV\lib\site-packages\pip\_vendor\pkg_resources.py", line 2573, in scan_list
    raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
ValueError: ('Expected version spec in', 'addons/pnc_tests', 'at', '/pnc_tests')

How to solve this problem?


Answers

I guess you are missing the parameter -r;

It must be like this if you have a requirement file to install from;

pip install -r addons/pnc_tests --upgrade --extra-index-url=http://some_server/simple

As it is defined on; Pip Documentation


One need to replace the slash (/) by a backslash (\):

pip install addons\pnc_tests --upgrade --extra-index-url=http://some_server/simple

On my system I had just specified the wrong directory. Double check your folder names. x_x


Because you can use a dynamic variable too:

somevar = 'foo'
getattr(x, somevar)

You can't do that with regular attribute access syntax.

Note that getattr() also takes an optional default value, to be returned if the attribute is missing:

>>> x = object()
>>> getattr(x, 'foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'foo'
>>> getattr(x, 'foo', 42)
42

Using getattr() you can pull the attribute name from something else, not a literal:

for attrname in dir(x):
    print('x.{} = {!r}'.format(attrname, getattr(x, attrname))

or you can use setattr() to set dynamic attributes:

for i, value in enumerate(dynamic_values):
    setattr(i, 'attribute{}'.format(i), value)




python windows