question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • 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!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Rflyeecommented, 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.

0reactions
pradyunsgcommented, Sep 7, 2018

Please look at #5599 for more details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: Module Pip has no attribute 'main'
You can choose to DOWNGRADE your pip version via following command: python -m pip install --upgrade pip==9.0.3.
Read more >
Attributeerror: Module Pip Has No Attribute 'Main' - ADocLib
If you are using pip and get the following import error: AttributeError: 'module' object has no attribute 'main' you can import main from...
Read more >
AttributeError: 'module' object has no attribute 'main'
Module object has no attribute error: Python. An attribute in Python means some property that is associated with a particular type of object...
Read more >
python pip: AttributeError: 'module' object has no attribute 'main'
The problem. This mean that you have installed pip 10 and the code you are executing is not compatible with pip 10.
Read more >
Changelog - pip documentation v22.3.1
Fix pip install --pre for packages with pre-release build dependencies defined both in ... A package in a wheel is (by definition) not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found