Using pip install
for any module apparently on my Ubuntu 16.04 system with python 2.7.11+ throws this error:
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
What is wrong with pip? How could I reinstall it, if necessary?
Update: Full traceback is below
sunny@sunny:~$ pip install requests
Collecting requests
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 512, in _prepare_file
finder, self.upgrade, require_hashes)
File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 273, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 442, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 400, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 545, in _get_pages
page = self._get_page(location)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 648, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 757, in get_page
"Cache-Control": "max-age=600",
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
timeout=timeout
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment
total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
First of all, this problem exists because of network issues, and uninstalling and re-installing everything won't be of much help. Probably you are behind proxy, and in that case you need to set proxy.
But in my case, I was facing the problem because I wasn't behind proxy. Generally, I work behind proxy, but when working from home, I set the proxy to None in Network settings.
But I was still getting the same errors even after removing the proxy settings.
So, when I did type
I found something like this :
And this was the reason I was still getting the very same error, even when I thought I had removed the proxy settings.
To unset this proxy, type
Follow the same approach for all the other entries, such as https_proxy.
For myself, it turns out that wlan0 was down, which resulted in me being unable to connect out. So, ensuring that wlan0 was up, allowed pip / pip3 to work without issue.
I have the same problem when installing a RaspberryPI TFT from Adafruit with pitft.sh / adafruit-pitft.sh.
I am not happy about coding-styles with errors from somewhere to be interpreted somehow - as could be seen by the previous answers.
Remark: The type error exception of retry.py is obviously a bug, caused by an unappropriate assignement and calculation of an instance of the class Reply to an int with the default value of 10 - somewhere in the code... Should be fixed either by adding an inplace-operator, or fixing the erroneous assignment.
So tried to analyse and patch the error itself first. The actual error in my case case is the same - retry.py called by pip.
The installation script adafruit-pitft.sh / pitft.sh tries to apply urllib3 which itself tries to install nested dependencies by pip, so the same error.
https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/master/adafruit-pitft.sh
https://github.com/adafruit/Raspberry-Pi-Installer-Scripts
For the current distribution(based on debian-9.6.0/stretch):
The following - dirty *:) - patch enables a sounding error trace:
The sounding output with the temporary patch is(displayed twice...?):
So in my case actually two things cause the error, this may vary in other environments:
My installation environment is offline from an internal debian+raspbian mirror, thus do not want to set the proxy...
So I proceeded by manual installation of the missing component evdev:
download evdev from PyPI(or e.g. from github.com):
https://pypi.org/project/evdev/
https://files.pythonhosted.org/packages/7e/53/374b82dd2ccec240b7388c65075391147524255466651a14340615aabb5f/evdev-1.1.2.tar.gz
Unpack and install manually as root user - for all local accounts, so detected as installed:
Call install script again:
If you proceed online by direct PyPI access:
check your routing + firewall for access to pypi.org
set a proxy if required (http_proxy/https_proxy)
And it works..
Hope this helps in other cases too.
Arno-Can Uestuensoez
----------------------------------------------
See also: issue - 35334: https://bugs.python.org/issue35334
----------------------------------------------
See now also: issue - 1486: https://github.com/urllib3/urllib3/issues/1486
for file: https://github.com/urllib3/urllib3/blob/master/src/urllib3/util/retry.py
I tried the solution answered above:
When I tried
I got this message
I did the following and it works
I also had this issue. Initially, a proxy was set and work fine. Then I connected to a network where it doesn't go through a proxy. After unsetting proxy pip again get works.
Solution:
1.
sudo apt remove python-pip
2.
pip3 install pip
(or install pip by get-pip.py)Why:
This error occurred on pip 8.0.1 which installed by apt-get. And happened only when your network is unstable.
If you have a pip installed with apt, it hides the pip you installed by other ways, so you should remove the apt one first.
I disconnected the network and tested 8.0.1, 9.0.3, 10.x the 3 versions installed with pip3 or get-pip.py, no error occurred. So, I think only the apt version of pip 8.0.1 has that bug, the others is ok.