Python PIP Install throws TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
Solution 1
Ubuntu comes with a version of PIP from precambrian and that's how you have to upgrade it if you do not want to spend hours and hours debugging pip related issues.
apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py
As you observed I included information for both Python 2.x and 3.x
Solution 2
If you are behind a proxy, you must do some extra configuration steps before starting the installation. You must set the environment variable http_proxy to the proxy address. Using bash this is accomplished with the command
export http_proxy="http://user:[email protected]:port/"
You can also provide the
--proxy=[user:pass@]url:port
parameter to pip. The [user:pass@]
portion is optional.
Solution 3
Updating setuptools has worked out fine for me.
sudo pip install --upgrade setuptools
Solution 4
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
env | grep proxy
I found something like this :
http_proxy=http://127.0.0.1:1234/
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
unset http_proxy
Follow the same approach for all the other entries, such as https_proxy.
Solution 5
What happens here is that the the vendored versions of request/urllib3 clash when imported in two different places (same code, but different names). If you then have a network error, it doesn't retry to get the wheel, but fails with the above error. See here for a deeper dive into this error.
For the solution with system pip, see above.
If you have this problem in a virtualenv built by python -m venv
(which still copies the wheels from /usr/share/python-wheels
, even if you have pip installed separately), the easiest way to "fix" it seems to be:
- create the virtualenv:
/usr/bin/python3.6 -m venv ...
- install
requests
into the environment (this might raise the above error):<venv>/bin/pip install requests
- remove the copied versions of
requests
which would be used by pip:rm <venv>/share/python-wheels/{requests,chardet,urllib3}-*.whl
Now a <venv>/bin/pip
uses the installed version of requests
which has urllib3 vendored.
Related videos on Youtube
devautor
Not a master at anything, never would be, but amidst these, I will learn, anything & everything I find fitting to satisfaction.
Updated on March 17, 2021Comments
-
devautor about 3 years
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'
-
Lukas Körfer over 6 yearsThis does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
-
Yogesh Gupta over 6 yearsDoes it look better now? I just thought i should mention what i found helpful
-
Arun Das over 6 yearsThis helped me big time in my OpenStack cluster !! Good one Deepak !
-
Eric over 6 yearsIt's not a solution: I run as root in docker and have the same issue. Also you don't explain why running as root helps.
-
Zeinab Abbasimazar over 6 years@Eric, I just used try&error approach; I don't know the underlying purpose. It worked for me, so I suggested.
-
krsoni over 6 yearsThanks, I just removed this
/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl
and it's fixed now (without virtualenv). -
krsoni over 6 yearsActually in my case, I was not using the virtual env.
-
Jan Katins over 6 yearsIf you remove the whl files directly in
/usr/share/python-wheels
,python -m venv
will not create a useable<venv>/bin/pip
anymore. So if you remove these files you should be sure that you do not need it. If you do need both a system pip and a venv pip, you need to do install the system one withget-pip.py
(See stackoverflow.com/a/37531821/1380673) and you need to remove the whl files in each venv. -
allan.simon about 6 yearsthe error happen to me while running this very exact command :(
-
Raúl Salinas-Monteagudo over 5 yearsIt fixed the error for me on a Raspbian Sketch Lite.
-
Stefan Wegener about 5 yearsI am also running Raspian Stretch Lite and it did not fix the error.
-
mayid almost 5 yearsWorked for me too. Actually, after doing this, I realised that the errors used to appear after: Collecting setuptools (from kiwisolver>=1.0.1->matplotlib)
-
imbatman almost 5 yearsI concur this worked beautifully "python -m pip install --upgrade pip"
-
Sam Hammamy over 4 yearsThis worked for me as well on an Raspian Stretch. Please accept this answer to make it easier to find
-
Pipo over 4 yearsneeded a reboot after that to bake it work with raspbian
-
sir__finley about 4 yearsThis command cause the same TypeError for me on Debian9. This is not universal solution.
-
gbarry over 3 yearsIf the top answer, "PIP from precambrian" is causing it, then this is an appropriate simple fix. Worked for me while attempting to install awscli...in Raspbian Stretch.