I want to install Scipy (already have Numpy installed). I have Python 3.5.1-3 installed with OS and IDLE3 (3.5.2). When I hit in terminal
sudo pip3 install scipy
It prints out
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
I've already tried to reinstall pip3 and restart OS, but it didn't change. Has pip3 been working weirdly with someone else?
Use
python -m pip install
instead ofpip install
Example:
I started getting this problem after a
pip
upgrade:The
pip
(resp.pip3
) executable is provided by your distro (python-pip
package on Ubuntu 16.04).Therefore, it is not kept up-to date with the
pip
package itself as you upgrade pip, and may break.If you just use
python -m pip
directly, e.g. as in:it goes through your Python path and finds the latest version of pip, and executes that file.
It relies on the fact that that file is executable, but that is a very standard type of interface, and therefore less likely to break than the hackier Debian script.
Then I recommend adding the following functions to your
.bashrc
:The Ubuntu 18.04
/usr/bin/pip3
file does:and presumably
main
was removed frompip
at some point which is what broke things.The breaking pip commit appears to be: 95bcf8c5f6394298035a7332c441868f3b0169f4 "Move all internal APIs to pip._internal" which went into pip 18.0.
Tested in Ubuntu 16.04 after an update from
pip3
9.0.1 to 18.0.pyenv
Ultimately however, for serious Python development I would just recommend that you install your own local Python with pyenv + virtualenv, which would also get around this Ubuntu bug: How do I install a different Python version using apt-get?
The bug is found in pip 10.0.0.
In linux you need to modify file: /usr/bin/pip from:
to this:
numpy and scipy are in the default repositories of all currently supported versions of Ubuntu. To install numpy and scipy for Python 3.x open the terminal and type:
For Python 2.x it's:
I had the same problem, but uninstall and reinstall with apt and pip didn't work for me.
I saw another solution that presents a easy way to recover pip3 path:
While karel may have solved your "install numpy and scipy" problem, what's wrong with pip on your system hasn't been addressed, so you'll probably have more problems with pip going forward.
Looking here, it seems to be a pretty common recent issue with pip 10 on Ubuntu systems. You may find some work arounds on that thread that work for you, but hopefully an update will fix it soon.
Installing pip from both apt and pip itself can cause this.
In my case, I used Ubuntu's pip package to install pipenv which then installed a newer copy of pip. Now because my shell runs Ubuntu's pip 9 script (to verify run
which pip3
) and my Python interpreter then imports the pip 10 module, the pip3 command fails. So I want to uninstall one of the two.It's fair to assume you have the newer pip for a reason. In that case you want to uninstall the older pip like so:
sudo apt remove python3-pip
If you know for sure that you're fine with the older pip and prefer the system package you'll want to uninstall the newer one:
~/.local/bin/pip3 uninstall pip
or failing that
sudo /usr/local/bin/pip3 uninstall pip
My issue ended up being a mismatch between python3.6 and 3.7. The python3.6 installation put a link in
/usr/bin/python3 -> /usr/bin/python3.6
even though the system had upgraded to python3.7.type
This should remove this error
Force reinstalling pip works just fine for most of the users as shown on this github page:
This worked for me:
By
install --upgrade
, I mean whatever you're trying to install.