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.

Cannot install under Ubuntu 18.04, breaks pip ("ImportError: cannot import name main")

See original GitHub issue

I want to install pipenv under Ubuntu 18.04. When I do so, it breaks pip / pip3.

Expected result

Installed and working version of pipenv.

Actual result

pip / pip3 are broken, depending on whether I wanted to install pipenv though pip or pip3.

➜ pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main
Steps to replicate
  1. Set up Ubuntu 18.04
  2. Run pip install pipenv or pip3 install pipenv
  3. Run pip or pip3 – the error is printed, and pip / pip3 do not work anymore.

In order to fix the issue I have to run:

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

But I cannot install pipenv using pip. Installation through apt does not work because there is no PPA available…


Solution

See the solution below; you need to have

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

in your shell configuration. If the path is not there, it won’t work.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:92
  • Comments:30 (18 by maintainers)

github_iconTop GitHub Comments

83reactions
slhckcommented, Oct 4, 2018

Ah, I see now what the problem is, thanks. Never thought that the path could influence this, which is why it didn’t occur to me to include it in the issue description. Sorry about that, and thanks for your help.

What fixed it for me was adding

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

to the profile.

Edit: Make sure you run hash -r or enter a new shell for this change to take effect.

I don’t think there is much we can do to independently tackle it

Perhaps there could be some more detailed installation instructions or caveats? I’m not too experienced with how pip works, but I might have read a note about path issues. But I guess that the ecosystem of different package managers and distributions is too complex for a simple rule…

9reactions
ConorSheehan1commented, Aug 28, 2018

edit: @slhck 's solution solved it. Need to have ~/.local/bin in your path

Getting the same problem on ubuntu 16.04.

$ sudo apt install python3-pip
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ python3 -m pip install --user pipenv
$ pip3 --version
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

# revert back and fix pip
$ sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error after upgrading pip: cannot import name 'main'
You can resolve this issue by reinstalling pip. Use one of the following command line commands to reinstall pip:.
Read more >
Running Pip3 ImportError: cannot import name 'main'
In my case, I used Ubuntu's pip package to install pipenv which then installed a newer copy of pip. Now because my shell...
Read more >
[SOLVED] Error after upgrading pip: cannot import name 'main'
This error mostly occurs when you have accidentally upgraded the pip in our system. · It appears when pip and unpack_url are used...
Read more >
ImportError cannot import name main in pip - Edureka
Hi Guys, I am getting this below error, when I am trying to install numpy in my system. $ pip3 ... import name...
Read more >
importerror: cannot import name 'main' from 'poetry.console'
To recover the pip3 binary you'll need to sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall . If you...
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