python pip: AttributeError: 'module' object has no attribute 'main'

The problem

If you were using main from pip after upgrading to pip 10 you will start to see errors like:

AttributeError: 'module' object has no attribute 'main'

You can also see the error:

from pip import main

ImportError: cannot import name main

This mean that you have installed pip 10 and the code you are executing is not compatible with pip 10.

Solution 1: use _internal module

The main function can be imported from module _internal like:

from pip._internal import main as _main

However note that the module name starts with underscore. Importing from a module that starts with underscore means it's private and you should not do this. If you want to know about these changes on pip, check Announcement: Pip 10 is coming, and will move all internal APIs

Solution 2: Downgrade pip

Actually this is not recommended, you can downgrade pip with:

pip install pip==9.0.1 

We suggest to use this solution only when you are using a library that needs to be updated.

Real Solution

The code of your application should not use unsupported internal APIs. You should change your code ot fix this issue.