DevOps | Cloud | Analytics | Open Source | Programming

How To Fix - "Cannot import name main Error in Python ?

In this post , we will see How To Fix - "Cannot import name 'main'" Error in Python. Sometimes while trying to install any package using pip, we get the the following import error:

ImportError: cannot import name 'main'

This mostly relates to the pip package manager . Probably the installed pip got upgraded in your system (Just FYI...Command to upgrade pip is -

sudo pip install pip --upgrade

Also note there might be a case that - You do have an original system pip (in /usr/bin/ and dist-packages/) . And one additional manually-installed pip (see in ~/.local/) . You need to resolve the conflict for these .   Lets see how this error can be resolved. There are couple of things , you could try as given below -

  • First thing first  - Check your pip site packages - where exactly it is installed. This is mostly related to the executable path being pointed. If you have multiple versions , check and add the those paths to the ./bashrc file.

$ which pip 

$ which pip3

export PATH="${HOME}/.local/bin:$PATH"

  • If you are using python 3+ , use below -

sudo apt install python3-pip --reinstall


  • If you are using Python 2 , use the below -

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

Hope this helps to resolve the issue.  

Additional Read -