Cannot install under Ubuntu 18.04, breaks pip ("ImportError: cannot import name main")
See original GitHub issueI 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
- Set up Ubuntu 18.04
- Run
pip install pipenv
orpip3 install pipenv
- Run
pip
orpip3
– 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:
- Created 5 years ago
- Reactions:92
- Comments:30 (18 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
to the profile.
Edit: Make sure you run
hash -r
or enter a new shell for this change to take effect.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…
edit: @slhck 's solution solved it. Need to have
~/.local/bin
in your pathGetting the same problem on ubuntu 16.04.