developer tip

Python PIP 설치에서 TypeError :-= : 'Retry'및 'int'에 대해 지원되지 않는 피연산자 유형이 발생합니다.

copycodes 2020. 9. 3. 20:05
반응형

Python PIP 설치에서 TypeError :-= : 'Retry'및 'int'에 대해 지원되지 않는 피연산자 유형이 발생합니다.


pip installPython 2.7.11+가 설치된 Ubuntu 16.04 시스템에서 모든 모듈을 사용하면 다음 오류가 발생합니다.

TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

핍에 어떤 문제가 있습니까? 필요한 경우 어떻게 다시 설치할 수 있습니까?

업데이트 : 전체 추적은 다음과 같습니다.

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'

Ubuntu는 선캄브리아 기의 PIP 버전과 함께 제공되며 pip 관련 문제를 디버깅하는 데 시간과 시간을 소비하지 않으려면 업그레이드해야합니다.

apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py

관찰 한대로 Python 2.x 및 3.x에 대한 정보를 포함했습니다.


프록시 뒤에있는 경우 설치를 시작하기 전에 몇 가지 추가 구성 단계를 수행해야합니다. 환경 변수 http_proxy를 프록시 주소로 설정해야합니다. bash를 사용하면 다음 명령으로 수행됩니다.

export http_proxy="http://user:pass@my.site:port/" 

당신은 또한 제공 할 수 있습니다

--proxy=[user:pass@]url:port 

pip에 대한 매개 변수. [user:pass@]부분은 선택 사항입니다.


우선,이 문제는 네트워크 문제로 인해 존재하며 모든 것을 제거하고 다시 설치하는 것은 큰 도움이되지 않습니다. 아마도 당신은 프록시 뒤에 있고이 경우 프록시를 설정해야합니다.

그러나 제 경우에는 프록시 뒤에 있지 않기 때문에 문제에 직면했습니다. 일반적으로 저는 프록시 뒤에서 일하지만 집에서 일할 때는 네트워크 설정에서 프록시를 없음으로 설정했습니다.

그러나 프록시 설정을 제거한 후에도 여전히 동일한 오류가 발생했습니다.

그래서 내가 타이핑했을 때

env | grep proxy

다음과 같은 것을 발견했습니다.

http_proxy=http://127.0.0.1:1234/

이것이 내가 프록시 설정을 제거했다고 생각했을 때에도 여전히 동일한 오류가 발생하는 이유였습니다.

이 프록시를 설정 해제하려면 다음을 입력하십시오.

unset http_proxy

https_proxy와 같은 다른 모든 항목에 대해 동일한 접근 방식을 따르십시오.


여기서 일어나는 일은 request / urllib3의 공급 업체 버전이 서로 다른 두 위치 (같은 코드이지만 다른 이름)에서 가져올 때 충돌한다는 것입니다. 그런 다음 네트워크 오류가 발생하면 휠을 가져 오기 위해 재 시도하지 않지만 위의 오류로 실패합니다. 이 오류에 대한 자세한 내용은 여기참조 하십시오 .

시스템 pip가있는 솔루션은 위의를 참조하십시오 .

에 의해 빌드 된 virtualenv에이 문제가있는 경우 (pip가 별도로 설치되어 있어도 python -m venv여전히에서 휠을 복사 함 /usr/share/python-wheels) "수정"하는 가장 쉬운 방법은 다음과 같습니다.

  1. virtualenv를 만듭니다. /usr/bin/python3.6 -m venv ...
  2. requests환경에 설치 (위의 오류가 발생할 수 있음) :<venv>/bin/pip install requests
  3. requestspip에서 사용할 복사 된 버전을 제거합니다 .rm <venv>/share/python-wheels/{requests,chardet,urllib3}-*.whl

이제 a 는 urllib3이 공급 된 <venv>/bin/pip설치된 버전을 사용합니다 requests.


setuptools 업데이트가 잘되었습니다.

sudo pip install --upgrade setuptools

포트 443이 열려 있지 않습니다. AWS에있는 경우 사용자 지정 tcp 포트 443 만 허용하고 그렇지 않으면 아웃 바운드 연결을 위해 포트 443을 엽니 다.


pip 업그레이드가 저에게 효과적이었습니다.

pip install --upgrade pip


.NET을 사용하는 모든 패키지 설치에 대해이 오류가 발생했습니다 pip. 나중에 그 핍이 필요 발견 http_proxyhttps_proxy프록시 뒤에 실행하는 변수입니다. 이 두 가지 환경 변수를 설정하면이 문제가 해결됩니다.

export http_proxy=http://<username>:<passowrd>@<proxy_ip>:<proxy_port>/
export https_proxy=https://<username>:<passowrd>@<proxy_ip>:<proxy_port>/

프록시 뒤에서 작업 할 때 이런 일이 발생합니다. 이 문제를 간단히 해결합니다.

pip install --proxy http : // proxyAddress : Port Package_To_Be_Installed


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.

adafruit-pitft.sh # or pitft.sh

...

_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'

For the current distribution(based on debian-9.6.0/stretch):

File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 315, in increment

total -= 1

TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

The following - dirty *:) - patch enables a sounding error trace:

# File: retry.py - in *def increment(self, ..* about line 315
# original: total = self.total

# patch: quick-and-dirty-fix
# START:
if isinstance(self.total, Retry):
    self.total = self.total.total

if type(self.total) is not int:
    self.total = 2 # default is 10
# END:

# continue with original:
total = self.total

if total is not None:
    total -= 1

connect = self.connect
read = self.read
redirect = self.redirect
cause = 'unknown'
status = None
redirect_location = None

if error and self._is_connection_error(error):
    # Connect retry?
    if connect is False:
        raise six.reraise(type(error), error, _stacktrace)
    elif connect is not None:
        connect -= 1

The sounding output with the temporary patch is(displayed twice...?):

Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at/

Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at/

Could not find a version that satisfies the requirement evdev (from versions: )

No matching distribution found for evdev

WARNING : Pip failed to install software!

So in my case actually two things cause the error, this may vary in other environments:

  1. Missing evdev => try to install
  2. Failed to connect a repo/dist containing evdev in order to download. => finally give it up

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:

  1. 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

  2. Unpack and install manually as root user - for all local accounts, so detected as installed:

    sudo su -

    tar xf evdev-1.1.2.tar.gz

    cd evdev-1.1.2

    python setup.py install

  3. Call install script again:

    adafruit-pitft.sh # or pitft.sh

    ...Answer dialogues...

    ...that's it.

If you proceed online by direct PyPI access:

  1. check your routing + firewall for access to pypi.org

  2. 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 was facing similar issue while trying to install awscli tool on ec2 instance. I changed security group to allow port 443 inbound and outbound access and that solved the issue for me.


I got this error when I was trying to create a virtualenv with command virtualenv myVirtualEnv. I just added a sudo before the command; it solved everything.


I tried the solution answered above:

apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py

When I tried

python get-pip.py 
python3 get-pip.py

I got this message

 Could not install packages due to an EnvironmentError:
[Errno 13] Permission denied: /usr/bin/pip3 Consider using the --user
 option or check the permissions.

I did the following and it works

python3 -m venv env
source ./env/bin/activate
Sudo apt-get update 
apt-get remove python-pip python3-pip
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
python3 get-pip.py
pip3 install pip
sudo easy_install pip
pip install --upgrade pip

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.

unset http_proxy; unset http_prox;  unset HTTP_PROXY; unset HTTPS_PROXY

Bizarrely if I remove the proxy from the environment and add it to the command line it works for me. For example to upgrade pip itself:

env http_proxy= https_proxy= pip install pip --upgrade --proxy 'http://proxy-url:80'

My issue was having the proxy in the environment. It seems that pip only honors the one in argument.


This is the working solution to this problem I found.

sudo apt-get clean
cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get clean
sudo apt-get update

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.


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.


In my case, i had opened Pycharm in sudo mode, and was running pip install nltk in pycharm terminal which showed this error. running with sudo pip install solves the error.


This problem is because your behind the proxy server just this command solve it:

sudo pip install requests --proxy="[user:passwd@]proxy.server:port"

And in case if you dont have username and password Just use the below command:

sudo pip install requests --proxy="proxy.server:port"

Example

sudo pip install requests --proxy="172.168.0.12:8088"

Cheers

참고URL : https://stackoverflow.com/questions/37495375/python-pip-install-throws-typeerror-unsupported-operand-types-for-retry

반응형