Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade mishap... ImportError: module 'pip' has no attribute 'main' #5487

Closed
joshistoast opened this issue Jun 10, 2018 · 5 comments
Closed

Comments

@joshistoast
Copy link

joshistoast commented Jun 10, 2018

  • Pip version: 10.0.1
  • Python version: 3.6.5
  • Operating system: MacOS 10.13.6

After having successfully upgrading to python 3.6.5, I noticed I was still on pip 9.0.3, so I had decided I would upgrade with the suggested prompt: pip install --upgrade pip.
Upon executing this... I get a traceback:

❯ pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 67kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
  Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
  File "/usr/local/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
  File "/usr/local/lib/python3.6/site-packages/pip/req/req_set.py", line 784, in install
  File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 851, in install
  File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
  File "/usr/local/lib/python3.6/site-packages/pip/wheel.py", line 462, in move_wheel_files
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/distlib/scripts.py", line 372, in make
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/distlib/scripts.py", line 276, in _make_script
    if self._is_nt and not outname.endswith('.' + ext):  # pragma: no cover
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/distlib/scripts.py", line 252, in _write_script
    outname = os.path.join(self.target_dir, name)
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/distlib/util.py", line 430, in <lambda>
    try:
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/distlib/util.py", line 428, in set_mode
    def socket_timeout(seconds=15):
PermissionError: [Errno 1] Operation not permitted: '/usr/local/bin/pip'

Having not read anything like the smart one I am... I ran python -m pip install pip --upgrade, to which I get:

Requirement already up-to-date: pip in /usr/local/lib/python3.6/site-packages (10.0.1)

After thinking it worked, I ran pip -V, what came next hurt me:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2332, in resolve
    return functools.reduce(getattr, self.attrs, module)
AttributeError: module 'pip' has no attribute 'main'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/python/libexec/bin/pip", line 11, in <module>
    load_entry_point('pip==9.0.3', 'console_scripts', 'pip3')()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2334, in resolve
    raise ImportError(str(exc))
ImportError: module 'pip' has no attribute 'main'

I searched the 7 seas, the heavens and the deepest depths of space to find related reports... but no solution worked for me!

Re-importing main:

❯ from pip._internal import main
from: can't read /var/mail/pip._internal

Re-installing an older version:

❯ pip install --upgrade pip==9.0.3
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2332, in resolve
    return functools.reduce(getattr, self.attrs, module)
AttributeError: module 'pip' has no attribute 'main'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/python/libexec/bin/pip", line 11, in <module>
    load_entry_point('pip==9.0.3', 'console_scripts', 'pip3')()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2334, in resolve
    raise ImportError(str(exc))
ImportError: module 'pip' has no attribute 'main'

I'm in dire need of a solution
Thanks in advance for any brave individuals who'd like to search this chasm of chaos with me and find the scroll of solutions!

@joshistoast
Copy link
Author

I still have yet to find out why in the blazes this happened... but after brew reinstall python3... pip seemed to be in perfectly working order. Understandably so since it must be bundled.

@Rflyee
Copy link

Rflyee commented Jul 11, 2018

This helps me, https://pip.pypa.io/en/stable/installing/
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
If you are using python3. do this,
python3 get-pip.py
It works for me.

@mgdeepak
Copy link

mgdeepak commented Jul 11, 2018

i tried updated pip3 in my mac and now it has stopped working and giving me below error whenever i am typing pip3 on terminal:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/pkg_resources/init.py", line 2326, in resolve
return functools.reduce(getattr, self.attrs, module)
AttributeError: 'module' object has no attribute 'main'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/pip3", line 11, in
load_entry_point('pip==7.1.2', 'console_scripts', 'pip3')()
File "/usr/local/lib/python3.4/site-packages/pkg_resources/init.py", line 476, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python3.4/site-packages/pkg_resources/init.py", line 2700, in load_entry_point
return ep.load()
File "/usr/local/lib/python3.4/site-packages/pkg_resources/init.py", line 2318, in load
return self.resolve()
File "/usr/local/lib/python3.4/site-packages/pkg_resources/init.py", line 2328, in resolve
raise ImportError(str(exc))
ImportError: 'module' object has no attribute 'main'

any suggestions?

@SRzhangbob
Copy link

SRzhangbob commented Sep 7, 2018

when i upgrade pip to 18.0,i get a traceback: ImportError: module 'pip' has no attribute 'main',this helps me:
python -m pip install pip
you can try! Then you can use pip

@pradyunsg
Copy link
Member

Please look at #5599 for more details.

@pypa pypa locked as resolved and limited conversation to collaborators Sep 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants