Archive

Posts Tagged ‘pip’

pip failed to install package

March 17, 2017 Leave a comment

Note to future self:

When installing a python package in a virtualenv using pip ie

pip install -r requirements.txt

If it fails to build and gives an error about something or the other.
Do a pip freeze and do a diff between what was installed and what is listed in requirements.txt

If there is a diff. Upgrade your pip version.

sudo pip install --upgrade pip

Try running the install again.

Advertisements
Categories: python Tags:

pip – ValueError: (‘Expected version spec in’…

December 20, 2016 Leave a comment

Problem:
I was not able to install a package from pip.

$ pip -V
pip 1.5.4 from /home/vagrant/envs/projects/local/lib/python2.7/site-packages (python 2.7)

$ less requirements.txt
--extra-index-url http://repository.example.com:6543/pypi/
--trusted-host repository.example.com

SQLAlchemy==1.1.4
flake8==3.2.1
mccabe==0.5.3
psycopg2==2.6.2
pyflakes==1.3.0
custom-application-from-repository==0.1.0

$ pip -r requirements.txt
Exception:
Traceback (most recent call last):
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/commands/install.py", line 262, in run
    for req in parse_requirements(filename, finder=finder, options=options, session=session):
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/req.py", line 1631, in parse_requirements
    req = InstallRequirement.from_line(line, comes_from, prereleases=getattr(options, "pre", None))
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/req.py", line 172, in from_line
    return cls(req, comes_from, url=url, prereleases=prereleases)
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/req.py", line 70, in __init__
    req = pkg_resources.Requirement.parse(req)
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/_vendor/pkg_resources.py", line 2606, in parse
    reqs = list(parse_requirements(s))
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/_vendor/pkg_resources.py", line 2544, in parse_requirements
    line, p, specs = scan_list(VERSION,LINE_END,line,p,(1,2),"version spec")
  File "/home/vagrant/envs/projects/local/lib/python2.7/site-packages/pip/_vendor/pkg_resources.py", line 2512, in scan_list
    raise ValueError("Expected "+item_name+" in",line,"at",line[p:])
ValueError: ('Expected version spec in', '--trusted-host repository.example.com', 'at', ' repository.example.com')

Storing debug log for failure in /home/vagrant/.pip/pip.log

Solution:
1. Upgrade pip. The version I was using does not accept the extra parameters specified in requirements.txt

$ pip -U install pip

2. Now run pip install command again.

Note:
1. Using a vagrant box running ubuntu trusty.

Ansible – Interactive scripts

May 20, 2016 Leave a comment

Problem:
Working with interactive scripts in Ansible 2. I need to change the shell from bash to zsh. Using the command chsh -s /usr/bin/zsh will prompt the user for their password. I am running this command on a vagrant box.

Solution:
Use expect.

This is what I added to my existing ansible script.

– name: “Install python pip”
become_user: root
apt: name=python-pip state=present

# expect needs pexpect to work.
– pip: name=pexpect version=3.3
become_user: root

– expect:
command: chsh -s /usr/bin/zsh
responses:
Password: vagrant

Source:
http://docs.ansible.com/ansible/expect_module.html
http://docs.ansible.com/ansible/pip_module.html

Categories: ansible Tags: ,