development

ImportError : windows7 32 비트에서 pip --version 명령을 실행할 때 main 이름을 가져올 수 없습니다

big-blog 2020. 6. 25. 07:29
반응형

ImportError : windows7 32 비트에서 pip --version 명령을 실행할 때 main 이름을 가져올 수 없습니다


Windows 32 비트 용 pip 및 setuptools와 함께 제공되는 최신 Python (2.7.9)을 설치했습니다. pip 재설치를 시도했지만 문제가 지속됩니다.

pip --version관리자 cmd에서 실행 한 후 발생한 오류는 다음과 같습니다 .

Traceback (most recent call last):
 File "D:\Python\lib\runpy.py", line 162, in _run_module_as_main
  "__main__", fname, loader, pkg_name)
 File "D:\Python\lib\runpy.py", line 72, in _run_code 
  exec code in run_globals
 File "D:\Python\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name main

버그는 pip 10.0.0에 있습니다.

리눅스에서는 / usr / bin / pip 파일을 다음에서 수정해야합니다.

from pip import main
if __name__ == '__main__':
    sys.exit(main())

이에:

from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

원래 질문은 2015 년의 것으로 보이지만이 '버그'는 설치하는 사용자에게도 영향을 미치는 것으로 보입니다 pip-10.0.0.

해결 방법은 수정하지 않지만 pippip 호출 방식을 변경하는 것입니다. 대신 호출 /usr/bin/pip전화를 pip파이썬을 통해. 예를 들어 아래 대신

pip install <package>

Python 버전 2 (또는 기본 Python 바이너리가 python) 인 경우 다음을 수행하십시오.

python -m pip install <package>

또는 파이썬 버전 3의 경우 :

python3 -m pip install <package> 

Ubuntu Server 16에서 python27과 동일한 문제가 있습니다. 이 시도:

변화

from pip import main
if __name__ == '__main__':
    sys.exit(main())

from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())

Windows 10에서는 다음 명령을 사용하여 pip를 다운 그레이드했습니다.

python -m pip uninstall pip
python -m pip install pip==9.0.3

이것은 Linux 및 Mac에서도 작동합니다.


나는 같은 문제가 있었지만 apt 및 pip로 제거하고 다시 설치하지 못했습니다.

pip3 경로를 쉽게 복구 할 수있는 다른 솔루션을 보았습니다.

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

을 사용하여 pip를 다시 설치하여 문제를 해결했습니다 get-pip.py.

  1. 공식 링크에서 get-pip를 다운로드하십시오 : https://pip.pypa.io/en/stable/installing/#upgrading-pip
  2. commande를 사용하여 실행하십시오 python get-pip.py.

그리고 핍은 고정되어 완벽하게 작동합니다.


MacOS에서 Homebrew를 통해 Python을 설치 한 경우 줄을 변경하십시오. /usr/local/opt/python/libexec/bin/pip

...에서

from pip.internal import main

from pip._internal import main

또는이 라이너를 사용하십시오 : sed -i '' "s/from pip import main/from pip._internal import main/" /usr/local/opt/python/libexec/bin/pip

설명:

The issue is caused by the changes in pip version 10 moving internal namespace under main._internal and the bin script put in place by homebrew still looking it from the old place (where it used to be in version 9). Issue and some discussion https://github.com/pypa/pip/issues/5240


If you have a hardlink to pip in your PATH (i.e. if you have multiple python versions installed) and then you upgrade pip, you may also encounter this error.

The solution consists in creating the hardlink again. Or even better, stop using hardlinks and use softlinks.


For those having similar trouble using pip 10 with PyCharm, download the latest version here


It works on ubuntu 16.04. Step 1:

 sudo gedit /home/user_name/.local/bin/pip

a file opens with the content:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

Change the main to __main__ as it appears below:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import __main__

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(__main__._main())

Save the file and close it. And you are done!


try this

#!/usr/bin/python
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.i
try:
    from pip import main
except ImportError:
    from pip._internal import main
if __name__ == '__main__':
    sys.exit(main())

A simple solution that works with Ubuntu, but may fix the problem on windows too:

Just call

pip install --upgrade pip

참고URL : https://stackoverflow.com/questions/28210269/importerror-cannot-import-name-main-when-running-pip-version-command-in-windo

반응형